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
Is This a Good Way to Model Address Information in a Relational Database
What Does a (+) Sign Mean in an Oracle SQL Where Clause
What Is the Meaning of Select ... for Xml Path(' '),1,1)
Database in Use Error with Entity Framework 4 Code First
How Do Null Values Affect Performance in a Database Search
SQL Insert into from Multiple Tables
How to Export Data from Excel Spreadsheet to SQL Server 2008 Table
T-Sql: Using a Case in an Update Statement to Update Certain Columns Depending on a Condition
Activerecord Find_Each Combined with Limit and Order
Select Rows with Same Id But Different Value in Another Column
How to Transfer or Export SQL Server 2005 Data to Excel
Do I Need to Create Indexes on Foreign Keys on Oracle