Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Not Exists is taking very long time!

$
0
0

Hi Team,

Not exists is taking very long time. ETL.Table1 has 50k records for recordtype = 1 and 49466 for recordtype =2. The difference is 534 for returning these records the query is taking close 4mins. Is there a way to improve the performance?

Declare @R1 Table
(
ConsumerID nVarchar(20)
)

Declare @R2 Table
(
ConsumerID nVarchar(20)
)

Insert into @R1
Select ConsumerID From ETL.Table1 Where RecordType='1'

Insert into @R2
Select ConsumerID From ETL.Table1 Where RecordType='2'

Select *
From @R1 R1
	Where Not Exists(Select ConsumerID from @R2 R2 Where R1.ConsumerID = R2.ConsumerID)


Thanks,

Eshwar.


Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>