我只是想知道如果table1和table2中的两个值相等,如何更新table1中的行。
例如,table1具有以下行:
id - password - attemp
user secret 0
user2 pass 0
和table2有行”
id - password
user secret
user2 kek
将table1 attemp值更新为table1 attemp = 1,其中table1用户和密码相等且table1 attemp = 0,
我做了这样的事情(它不起作用):
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句