Update Query Using Subquery in SQL Server

Update query using Subquery in Sql Server

you can join both tables even on UPDATE statements,

UPDATE  a
SET a.marks = b.marks
FROM tempDataView a
INNER JOIN tempData b
ON a.Name = b.Name
  • SQLFiddle Demo

for faster performance, define an INDEX on column marks on both tables.

using SUBQUERY

UPDATE  tempDataView 
SET marks =
(
SELECT marks
FROM tempData b
WHERE tempDataView.Name = b.Name
)
  • SQLFiddle Demo

subqueries in UPDATE SET (sql server 2005)

You can try something like

UPDATE  trips
SET locations = t.city + ', ' + poi.city
FROM trips t INNER JOIN
(
select Distinct city, trip_guid from poi
) poi ON t.trip_guid = poi.trip_guid


Related Topics



Leave a reply



Submit