Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to UPDATE statement with JOIN in SQL Server?

I want to update this table in SQL Server with data from its 'parent' table, see below:

Table: sale*

id (int)
udid (int)
assid (int)

*Table: ud


id (int)
assid (int)

sale.assid contains the correct value to update ud.assid.

What query will do this? I'm thinking of a join but I'm not sure if it's possible.
by

2 Answers

Sonali7
The following code can be implemented in SQL Server to UPDATE statement with JOIN:

update u
set u.assid = s.assid
from ud u
inner join sale s on
u.id = s.udid
espadacoder11
A standard SQL approach would be

UPDATE ud
SET assid = (SELECT assid FROM sale s WHERE ud.id=s.id)
On SQL Server you can use a join


UPDATE ud
SET assid = s.assid
FROM ud u
JOIN sale s ON u.id=s.id

Login / Signup to Answer the Question.