Q:

Insert into row if value exists in a different table

I have two tables:
Users:
+---------------------+---------------------+
|        UserId       |    ValueToUpdate    |
+---------------------+---------------------+
|          1          |                     |
|          2          |                     |
|          3          |                     |
+---------------------+---------------------+

Subscribers:
+---------------------+
|        UserId       |
+---------------------+
|          1          |
|          2          |
+---------------------+

I need to write a SQL query that will insert some value into the Users table, column (ValueToUpdate) if the user id in the Users table exists in the Subscribers table.
Essentially I'm looking for something like this
 UPDATE Users 
 SET ValueToUpdate = "some value" 
 WHERE (UserId from the Users table exists in the Subscribers table);

How could I achieve this?

A:

You can do this using an exists clause:
 UPDATE Users u
 SET ValueToUpdate = 'some value'
 WHERE EXISTS (SELECT 1 FROM Subscribers S WHERE s.userid = u.userid);

