简体   繁体   中英

Update values in table from another table in sql unable to understand what missing

I came across situation where now I want to update the table but i want values which will come from another table. I have written fowllowing SQL , I am sure this is very foolish question , but this is last patterm which will complete my module and need to do this ASAP

UPDATE t 
SET t.col1 = o.col1, 
    t.col2 = o.col2
FROM 
    other_table o 

WHERE 
    o.sql = 'cool'

you missin join

UPDATE t 
SET t.col1 = o.col1, 
    t.col2 = o.col2
FROM 
    other_table o 
  JOIN 
    t ON t.id = o.id
WHERE 
    o.sql = 'cool'

You can try it using JOINS like

UPDATE t
SET
    t.col1 = o.col1, 
    t.col2 = o.col2
FROM
    t
INNER JOIN
    other_table o
ON t.id = o.id
WHERE 
    o.sql = 'cool'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM