Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
II Traveler II
Starting Member
11 Posts |
Posted - 2011-10-31 : 19:21:58
|
| So I have coded the following query, but I want to use a subquery instead of a join. How would I go about doing that?UPDATE InvoiceCopySET TermsID = 2FROM InvoiceCopy JOIN VendorsCopy ON InvoiceCopy.VendorID = VendorsCopy.VendorIDWHERE VendorsCopy.DefaultTermsID = 2 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 04:30:01
|
| why you want to use subquery instead? if you've proper indexes, join works much better than subquery especially when amount of data is large------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 04:30:57
|
however this might work betterUPDATE InvoiceCopySET TermsID = 2WHERE EXISTS(SELECT 1 FROM VendorsCopy WHERE InvoiceCopy.VendorID = VendorsCopy.VendorIDAND VendorsCopy.DefaultTermsID = 2) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
II Traveler II
Starting Member
11 Posts |
Posted - 2011-11-01 : 16:13:20
|
| Thanks so much visakh16! Works like a charm. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-02 : 05:27:46
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|