使用来自另一个表的值更新postgresql表

use*_*217 2 sql postgresql sql-update

比方说,我有表table1的列idvaluetable2与列table1_idvalue

如果匹配,我将如何编写Postgresql查询来更新table1.value(整个表,而不仅仅是一行)?table2.valuetable1.id = table2.table1_id

预先感谢您的答复!

Gor*_*off 5

您使用一个from子句。在Postgres中,这看起来像:

update table1
    set col1 = . . .
    from table2
    where table1.id = table2.table1_id
Run Code Online (Sandbox Code Playgroud)

  • 这是大量数据的最佳实践吗? (2认同)