1

I have 2 tables, users and profiles. And I'd like to set profiles.verified to true if users.emails is in a list ('email1','email2',...).

Inspired by other SO threads like updating table rows in postgres using subquery, I've been trying to do something like,

UPDATE 
  profiles p1  
SET 
  verified = true
FROM 
  profiles p2
  INNER JOIN users u1 on u1.id = p2.user_id
WHERE 
  u1.email in ('email1','email2',...)

But it just updates profiles.verified to true for all records in profiles.

How can I only update profile records if they are related to a users record with an email in a specified list?

1 Answer 1

1

In Postgres, you don't mention the table being updated twice:

UPDATE profiles p1  
    SET verified = true
FROM users u1 
WHERE u1.id = p1.user_id AND
      u1.email in ('email1', 'email2', ...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.