smith February 2016

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'

Answers


Pushkar Phule February 2016

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'


Rahul Tripathi February 2016

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'

Post Status

Asked in February 2016
Viewed 2,646 times
Voted 14
Answered 2 times

Search




Leave an answer