![](/img/trans.png)
[英]How to update MYSQL table from HTML form with single column of checkboxes
[英]how to update column from multiple table in mysql
嗨,大家好,我想更新兩個表格中的列。
例如: abc
和xyz
。 abc
表包含名為id
, fname
, lastname
, status
字段。 並且表xyz
包含id
, x_id
和status
。 現在,我要使用單個查詢更新abc
的列狀態和xyz
的status
列。
我嘗試此查詢,但是它不起作用。
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.