0

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'
smith
  • 35
  • 5
  • Possible duplicate of [Update a table using JOIN in SQL Server?](http://stackoverflow.com/questions/1604091/update-a-table-using-join-in-sql-server) – Ullas Feb 08 '16 at 08:21

2 Answers2

3

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'
Pushkar Phule
  • 160
  • 11
0

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'
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331