0

I am trying to update users.banned values only where the age is 21, and the users_auth.email matches the ban_users.email. (ban_users is a separate table)

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

How do I UPDATE from a SELECT in SQL Server?

Thanks for the help.

Community
  • 1
  • 1
Changerrs
  • 273
  • 1
  • 4
  • 17

2 Answers2

0

Try this:

UPDATE ua
SET banned = '1'
FROM users_auth ua
INNER JOIN ban_users
ON ua.email = ban_users.email
WHERE age='21'
www
  • 4,365
  • 1
  • 23
  • 24
0

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'
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63