我想替换表格中的一列数据。
表A
Uid - int
AnotherUid - int
表B
Uid - int
TableA.uid = Table.B uid 我正在尝试用TableA.AnotherUid替换TableB.Uid
Select * from TableB a, TableA b where a.uid=b.uid
update TableB set a.uid=b.AnotherUid
我在TableB设置a.uid = b.AnotherUid时从MySQL得到了SQL语法错误。
请帮助。
答案 0 :(得分:6)
UPDATE TableB T
SET T.uid =
(SELECT AnotherUid
FROM TableA A
WHERE A.uid = T.uid)
答案 1 :(得分:6)
UPDATE TableB SET TableB.Uid = (SELECT AnotherUid FROM TableA WHERE TableA.Uid = TableB.Uid)
答案 2 :(得分:2)
尝试此查询:
Update TableB, TableA
Set TableB.uid = TableA.AnotherUid
Where TableB.uid = TableA.uid;
有关在Update更新查询中加入的MySQL手册,请参阅:http://dev.mysql.com/doc/refman/5.0/en/update.html并在其文档中查看此示例:
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;