views:

63

answers:

3

How to write this MySQL update statement:

table1 identity

table2 memberid, username, email

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?

A: 

UPDATE [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

Woot4Moo
A: 
UPDATE table1, table2
SET table1.indentity = table2.memberid 
WHERE table1.FOREIGNKEYHERE = table2.PRIMARYKEYHERE;
Zurahn
Great! Thank you, @Zurahn
Steven
A: 

Borrowed from MindStalker:

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