简体   繁体   English

如何编写此MySQL更新语句?

[英]How to write this MySQL update statement?

How to write this MySQL update statement: 如何编写此MySQL更新语句:

table1 identity table1身份

table2 memberid, username, email table2会员编号,用户名,电子邮件

Some values in identity of table1 are email, some are username, how to replace the values in identity of table1 with the corresponding value of memberid of table2? table1身份中的某些值是email,一些是用户名,如何用table2的memberid的对应值替换table1中身份的值?

UPDATE table1, table2
SET table1.indentity = table2.memberid 
WHERE table1.FOREIGNKEYHERE = table2.PRIMARYKEYHERE;

UPDATE [LOW_PRIORITY] [IGNORE] table_reference 更新[LOW_PRIORITY] [IGNORE] table_reference

SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...

[WHERE where_condition]

[ORDER BY ...]

[LIMIT row_count]

from: http://dev.mysql.com/doc/refman/5.0/en/update.html 来自: http : //dev.mysql.com/doc/refman/5.0/en/update.html

Borrowed from MindStalker : 从MindStalker借来的

UPDATE table1, table2
SET table1.identity=table2.memberid
WHERE table1.identity=table2.username or table1.identity=table2.email;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM