I'm trying to build following query :
INSERT INTO table1 (field1, field2)
VALUES (field1, field2) FROM table2
WHERE table2.id = table1.id
Logically I get a "more than one row returned by a subquery used as an expression" error because of the WHERE condition, but can't get the clue how to solve it, nor find matching case in existing posts as for now. I've tested this approach but it fails ...
Thanks for any help
I suspect that what you actually want is update the rows of table1
with the matching rows of table2
:
UPDATE table1 AS t1
SET (field1, field2) = (t2.field1, t2.field2)
FROM table2 AS t2
WHERE t2.id = t1.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With