开发者

Replace a column of data with another column from another table

开发者 https://www.devze.com 2023-02-18 09:00 出处:网络
I would like to replace a column of data in a table. TableA Uid- int AnotherUid- int TableB Uid- int TableA.uid = Table.B uid

I would like to replace a column of data in a table.

TableA

Uid - int

AnotherUid - int

TableB

Uid - int

TableA.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;
0

精彩评论

暂无评论...
验证码 换一张
取 消