Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

T-SQL alternative to NOT IN

Status
Not open for further replies.

maxwell2323

Programmer
Sep 22, 2008
12
US
Can you help me with an alternative that might be more efficient and quicker than what I have in these few lines. I am inserting some records from a temp table into another table that already has records, and I have just one condition. Here is my code:

Insert into #MainTable
Select * from #Results3 as R3
Where R3.PatGuid NOT IN
(Select Pat.Guid from #MainTable)

--Thanks !!!!!!!!!
 
Code:
Insert into #MainTable
Select * 
       from #Results3 as R3
LEFT JOIN #MainTable ON  R3.PatGuid = #MainTable.PatGuid
WHERE #MainTable.PatGuid IS NULL

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Borislav,
I tend to use the format in your example (left join) - do you think this is faster than a NOT EXISTS or NOT IN? I've never got around to testing such, but am curious.
Thanks & happy Friday!
lex

soi là, soi carré
 
markros,
Thanks - I should have addressed my post to you also!

soi là, soi carré
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top