Query from Table A for all records that do not appear in table B for the associated field. Now two data tables have data probably about 25,000 records, b table relative a table less than 230 records, so to query a table more out of the record, the association field is a table ID and B table aid, the query method is commonly used in three ways
| The code is as follows |
Copy Code |
Select a.ID from a LEFT join B in A.id=b.aid where B.aid is NULL; Select a.ID from a where a.id to (select B.aid from B); Select a.ID from a Where NOT EXISTS (select null from B where b.aid=a.id); |
Result of is null method with join: 230 rows in Set (min 0.48 sec)
Not in method result: 230 rows in Set (min 7.48 sec)
Not EXISTS method Result: 230 rows in Set (Panax min 52.44 sec)
Dizzy, why all is so slow? What's wrong?
The original B table of aid did not build the index, indexing after the query on a lot of faster, Index after the query three kinds of methods are probably only 0.52sec out of the results, the index and no index will have such a strong difference, so for this query, be sure to index the associated fields Oh, or you can only accept the Turtle Xun!