[英]UPDATE on inner join with another table
I am trying to update users.banned values only where the age is 21, and the users_auth.email matches the ban_users.email. 我试图仅在年龄为21的情况下更新users.banned值,并且users_auth.email与ban_users.email匹配。 (ban_users is a separate table)
(ban_users是一个单独的表)
UPDATE users_auth
SET users_auth.banned = '1'
WHERE age='21'
INNER JOIN ban_users
ON users_auth.email = ban_users.email
I have found these two posts but both dont seem to help. 我找到了这两个帖子,但两个似乎都没有帮助。
SQL Server - inner join when updating SQL Server - 更新时的内部联接
How do I UPDATE from a SELECT in SQL Server? 如何从SQL Server中的SELECT更新?
Thanks for the help. 谢谢您的帮助。
Try this: 尝试这个:
UPDATE ua
SET banned = '1'
FROM users_auth ua
INNER JOIN ban_users
ON ua.email = ban_users.email
WHERE age='21'
The syntax is not correct it should be as below. 语法不正确,应如下所示。
UPDATE users_auth
INNER JOIN ban_users
ON users_auth.email = ban_users.email
SET users_auth.banned = '1'
WHERE age='21'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.