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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Converting a join to a subquery in this query

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 InvoiceCopy
SET TermsID = 2
FROM InvoiceCopy JOIN VendorsCopy ON InvoiceCopy.VendorID = VendorsCopy.VendorID
WHERE 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-01 : 04:30:57
however this might work better


UPDATE InvoiceCopy
SET TermsID = 2
WHERE EXISTS(SELECT 1 FROM VendorsCopy WHERE InvoiceCopy.VendorID = VendorsCopy.VendorID
AND VendorsCopy.DefaultTermsID = 2)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

II Traveler II
Starting Member

11 Posts

Posted - 2011-11-01 : 16:13:20
Thanks so much visakh16! Works like a charm.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 05:27:46
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -