How can I do an UPDATE statement with JOIN in SQL Server?

Submitted 3 years, 4 months ago
Ticket #324
Views 264
Language/Framework SQL
Priority Low
Status Closed

Need to update this table in SQL Server with data from its 'parent' table

Submitted on Dec 12, 20
add a comment

1 Answer

Verified

Try this:
 

UPDATE child_table AS ct
SET ct.field1 = value1,
    ct.field2 = value2
FROM ct 
JOIN parent_table AS pt 
ON ct.field3 = pt.field3 AND ct.field4 = pt.field4
WHERE 
ct.field1 = some_val 

For a better answer, provide some usefull examples with real data.
Your question is to abstract to get a good answer.

Submitted 3 years, 4 months ago


Latest Blogs