Go A, b two tables, find the ID field, there is a table, but there is no data in table B. A total of 13w data, after the deduplication of about 3W data, b table has 2W data, and B table ID field is indexed.
Method One
Use not in, easy to understand, low efficiency ~ Execution Time: 1.395 seconds ~ (the first method of pro-test is available)
1Selectdistinct a.id from A where a.id not in (select ID from B)
Method Two
Use left Join...on ..., "b.id isnull" indicates a record of NULL in the b.ID field after you have connected-the execution time: 0.739 seconds ~
1Select a.IDFrom Aleft join B On a.ID = b.ID where b.ID is null
Graphic
Method Three
Logic is relatively complex, but the fastest ~ execution time: 0.570 seconds ~ (feeling this way is very good)
1 from B
2Where (SelectCount 1) as num from A where a.id = b.id) = 0
(turn) query A, B table, a table in the existence of table B does not exist data