Reputation: 2444
I have two tables: A, B.
Here's what I want to do (this is obviously not valid SQL):
UPDATE A a, B b SET a.pic = b.pic WHERE a.my_id = b.my_id
i.e. when the column my_id matches in tables A and B, I want to copy the pic column from B to A.
What's the right way of doing this?
Upvotes: 1
Views: 116
Reputation: 28531
The correct postgres query:
UPDATE A a
SET pic = b.pic
FROM B b
WHERE a.my_id = b.my_id;
Upvotes: 1
Reputation: 6826
You're only really updating A (and you can only update one table in an an UPDATE statement anyways)
UPDATE A a SET a.pic = ( SELECT b.pic FROM B b WHERE a.my_id = b.my_id)
Upvotes: 0