Replace data column with another column from another table

I would like to replace the data column in the table.

Tablea
Uid - int
AnotherUid - int

Tableb
Uid - int

TableA.uid = Table .B uid And I'm trying to replace 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 in TableB set by a.uid = b.AnotherUid.

Please, kindly help.

+4
source share
3 answers
 UPDATE TableB T SET T.uid = (SELECT AnotherUid FROM TableA A WHERE A.uid = T.uid) 
+6
source
 UPDATE TableB SET TableB.Uid = (SELECT AnotherUid FROM TableA WHERE TableA.Uid = TableB.Uid) 
+5
source

Try this query:

 Update TableB, TableA Set TableB.uid = TableA.AnotherUid Where TableB.uid = TableA.uid; 

For MySQL guidance on connecting in an update request, refer to http://dev.mysql.com/doc/refman/5.0/en/update.html and see this example in your document:

 UPDATE items,month SET items.price=month.price WHERE items.id=month.id; 
+2
source

Source: https://habr.com/ru/post/1344873/


All Articles