Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a column of data with another column from another table

Tags:

database

mysql

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 TableB 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.

like image 311
Alocus Avatar asked Dec 05 '22 23:12

Alocus


1 Answers

UPDATE TableB T
   SET T.uid = 
     (SELECT AnotherUid 
     FROM TableA A
     WHERE A.uid = T.uid)
like image 88
jon_darkstar Avatar answered Dec 10 '22 09:12

jon_darkstar