![](/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.