SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 JOIN vs NESTED SQL: Which is faster?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MMMY
Starting Member

14 Posts

Posted - 08/15/2012 :  19:03:09  Show Profile  Reply with Quote
Updating a table... Which would be faster? Or is there an even better option? Thanks!

QUERY 1
Update A
Set A.1 = B.1,
A.2 = B.2
From A
Join B on A.3 = B.3

QUERY 2
Update A
Set A.1 = (Select B.1 From B Where A.3 = B.3),
A.2 = (Select B.2 From B Where A.3 = B.3)

Edited by - MMMY on 08/15/2012 19:04:13

chadmat
The Chadinator

USA
1962 Posts

Posted - 08/15/2012 :  19:06:06  Show Profile  Visit chadmat's Homepage  Reply with Quote
I suspect Query 1 would be faster (Query 2 isn't a valid query, but I get what you mean)

-Chad
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29156 Posts

Posted - 08/16/2012 :  03:25:31  Show Profile  Visit SwePeso's Homepage  Reply with Quote
There is a logical difference between the two queries.
If there is no match between A table and B table; with query 2 the old values for colunms 1 and 2 remains the same as before.
With Query 2 (if there is no match) the values are replaced with a NULL values.

Query 2 also have the risk for failure if there are more than 1 match between table A and B.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000