我只是想知道如果 table1 和 table2 中的几个值相等,如何更新 table1 中的行。
例如,table1 有行:
id - password - attemp
user secret 0
user2 pass 0
table2 有行”
id - password
user secret
user2 kek
将 table1 attemp 值(其中 table1 用户和密码相同且 table1 attemp = 0)更新为 table1 attemp = 1
我做了这样的事情(但它不起作用):
UPDATE a1
set a1.attemp = '1'
from table1 a1
JOIN table2 a2
on a1.user = a2.user AND a1.password = a2.password
WHERE
a1.attemp != 1
最佳答案
试试这个:
UPDATE table1 a1
INNER JOIN table2 a2 ON a1.id = a2.id AND a1.password = a2.password
SET a1.attemp = '1'
WHERE a1.attemp != '1'
这将导致:
ID PASSWORD ATTEMP
user secret 1
user2 pass 0
关于mysql - 满足几个条件的sql设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19980788/