[英]Update sql table using inner join
i'm trying to update my sql table using inner join. 我正在尝试使用内部联接更新我的sql表。 I have 2 tables:
users
and warnings
我有2个表:
users
和warnings
So i want to update my users
table and set value 'yes' to filed users.awarn
where users.id_level = '3'
and inner join table warnings
using id and check if warnings.active = 'yes'
所以我想更新我的
users
表并为归档的users.awarn
设置值'yes' ,其中users.id_level = '3'
,内部users.id_level = '3'
表warnings
使用id并检查warnings.active = 'yes'
bellow is my command: 吼叫是我的命令:
UPDATE users
SET users.awarn = 'yes'
INNER JOIN warnings
ON users.id = warnings.userid
WHERE users.id_level = '3'
AND warnings.active = 'yes'
but phpmyadmin return syntax error. 但phpmyadmin返回语法错误。 Thanks in advance!
提前致谢!
This is the correct syntax for MySQL: 这是MySQL的正确语法:
UPDATE users INNER JOIN
warnings
ON users.id = warnings.userid
SET users.awarn = 'yes'
WHERE users.id_level = '3' AND warnings.active = 'yes';
Your order of operation is wrong SET has to come after JOIN so: 您的操作顺序错误SET必须在JOIN之后进行,所以:
UPDATE users
INNER JOIN warnings
ON users.id = warnings.userid
SET users.awarn = 'yes'
WHERE users.id_level = '3'
AND warnings.active = 'yes'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.