I have large table with many column and I need to update whole table with select statement. How can I update whole table selecting from another table in postgress?
Asked
Active
Viewed 147 times
0
-
1To update a table you need an UPDATE query, not a select. You mean update on table, with SELECT of data from another table ? – itsmarwen Nov 07 '22 at 13:46
-
@SonOfHarpy ya I mean to update table by selecting from another table. Edit has been made – Awesome Nov 07 '22 at 13:47
-
I think you'll find what you need : https://stackoverflow.com/questions/1746125/update-columns-values-with-column-of-another-table-based-on-condition – itsmarwen Nov 07 '22 at 13:50
1 Answers
0
I Think This is what you need :
UPDATE table_a
SET info = table_b.info
FROM table_b
WHERE table_a.id = table_b.id
updated according to @a_horse_with_no_name

itsmarwen
- 131
- 1
- 3
- 14
-
[As documented in the manual](https://www.postgresql.org/docs/current/sql-update.html#id-1.9.3.183.6) the target table of an UPDATE should **not** be repeated in the FROM clause. – Nov 07 '22 at 14:11