簡體   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