I would like to replace a column of data in a table.
TableA
Uid - int AnotherUid - intTableB
Uid - intTableA.uid = Table.B uid And I am trying to replace the TableB.Uid with TableA.AnotherUid
Select * from Tabl开发者_StackOverfloweB a, TableA b where a.uid=b.uid
update TableB set a.uid=b.AnotherUid
I got a SQL syntax error from MySQL at TableB set a.uid=b.AnotherUid.
Please kindly help.
UPDATE TableB T
SET T.uid =
(SELECT AnotherUid
FROM TableA A
WHERE A.uid = T.uid)
UPDATE TableB SET TableB.Uid = (SELECT AnotherUid FROM TableA WHERE TableA.Uid = TableB.Uid)
Try this query:
Update TableB, TableA
Set TableB.uid = TableA.AnotherUid
Where TableB.uid = TableA.uid;
For MySQL manual on join in the Update query please refer: http://dev.mysql.com/doc/refman/5.0/en/update.html and see this example in their doc:
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;
精彩评论