[英]How to update multiple columns with a single select query in MySQL?
Let take a example, there are two tables as bellow. 让我们举个例子,下面有两个表。
OldData
-----------
id
name
address
NewData
-----------
nid
name
address
I want to update OldData
table with NewData
table. 我想用
NewData
表更新OldData
表。
For that purpose I am trying to use the following query: 为此,我尝试使用以下查询:
UPDATE OldData SET (name, address) = (SELECT name, address FROM NewData WHERE nid = 234)
WHERE id = 123
But it gives a syntax error. 但是它给出了语法错误。
What is the proper way of doing what I try? 做我尝试的正确方法是什么?
UPDATE OldData o, NewData n
SET n.name = o.name, n.address = o.address
where n.nid=234 and o.id=123;
尝试这个:
Update oldData set name = (select name from newData where nid = 234),address = (select address from newData where nid = 123);
Try This : 尝试这个 :
UPDATE OldData a,NewData b
SET a.name = b.name , a.address = b.address
WHERE a.id=123 AND b.nid = 234
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.