PostgreSQL - Using a Subquery to Update Multiple Column Values

后端 未结 7 939
无人共我
无人共我 2021-02-02 08:01

I need to be able to update multiple columns on a table using the result of a subquery. A simple example will look like below -

UPDATE table1
SET (col1, col2) =         


        
相关标签:
7条回答
  • 2021-02-02 08:30

    This isn't the most efficient way to do this, but it's simple:

    UPDATE table1 SET
    col1 = (SELECT MIN (ship_charge) FROM orders),
    col2 = (SELECT MAX (ship_charge) FROM orders)
    WHERE col4 = 1001; 
    
    0 讨论(0)
提交回复
热议问题