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

Find missing IDs using high performance query

$
0
0

I have two tables. The first table contains IDs (unique records), say, 100,000.

The second table does not contain all IDs of first table but may contain duplicate values.

First Table

ID  int     P.K

Name varchar(50)

Second Table

ID    int   F.K

Salary   decimal(10,2)

I want to get all IDs from first table which are not in the second table using a high performance query.

Initially, I thought a poor way like:

select ID from table1 where ID not in (select distinct ID from table2)

Later, I worked out something like:

select A.ID from table1 A
left join table2 B
on A.ID = B.ID
and salary is null
Is there any other way to get results with a high performance query?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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