Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
INNER JOIN on UPDATE with WHERE updating every record in Postgres

I'm trying to update a single record and return the email of the owner of the updated record by doing INNER JOIN de ID of the createdby which links to the users table.

Here's the query:

UPDATE requests
SET statusid = 2
FROM requests AS r
INNER JOIN users
ON r.createdby = users.id
WHERE r.id =10
RETURNING r.id, users.email;

But this will update every record instead of using the WHERE.

What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In Postgres, you do not repeat the table being updated in the FROM. So:

UPDATE requests r
    SET statusid = 2
    FROM users u
    WHERE r.createdby = u.id AND r.id =10
RETURNING r.id, u.email;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!