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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query

Status
Not open for further replies.

happyIndian100

Programmer
Jul 20, 2003
66
US
Please Help!!!

Is there any better way to write this query to improve performance. Total Records are 5,00,000 records

Select Distinct A.col1
,Null Col2
,A.Col3
,Null Col4
,A.Col5
From Table1 A
Where Not Exists ( Select * From Table2 B
Where A.Col1 = B.Col1
And A.Col5 = B.Col5 )

Thanks
 
start by removing the DISTINCT (unless you know for sure that there are dups of the Col1/Col3/Col5 combination)

try also:
Code:
select A.col1
     , null Col2
     , A.Col3
     , null Col4
     , A.Col5
  from Table1 A
left outer
  join Table2 B
    on A.Col1 = B.Col1
   and A.Col5 = B.Col5 
 where B.col1 is null

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top