繁体   English   中英

如何从MySQL中的多个表更新列

[英]how to update column from multiple table in mysql

嗨,大家好,我想更新两个表格中的列。

例如: abcxyz abc表包含名为idfnamelastnamestatus字段。 并且表xyz包含idx_idstatus 现在,我要使用单个查询更新abc的列状态和xyzstatus列。

我尝试此查询,但是它不起作用。

UPDATE abc a1 
JOIN xyz x1 ON a1.id = x1.x_id 
SET a1.status = "D" , 
    x1.status = "delete" 
WHERE a1.id = 15 AND x1.x_id = 15;  

谢谢。

编辑了3个表格:

UPDATE a1,x1,s1 
SET a1.status = "D" , 
x1.status = "delte",
s1.status = "D" 
WHERE a1.id = x1.x_id
AND a1.id = s1.s_id 
AND a1.id = 15;

如果您的mysql服务器无法使用SQL在单个查询中更新两个表。 您可以使用LOCK TABLES命令来避免竞争情况:

LOCK TABLES abc WRITE, xyz WRITE;
update abc set status = "D"  where id = 15;
update xyz set status = "delete"  where x_id = 15;
UNLOCK TABLES;

问候,奥马尔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM