devxlogo

Unmatched Query

Unmatched Query

Question:
When one is working with large amounts of data, what is the quickest way of displaying rows not found when comparing two tables, without doing the following:

SELECT table1.field1 FROM Table1 WHERE Table1.field1 NOT IN (SELECT Table2.field1 FROM Table2)

Answer:
When possible, you should always use the exists clause instead of the IN clause. Exists is more efficient.

 So select * from table1 wherenot exists(select * from table2 wheretable1.col1 = table2.col2)

devx-admin

Share the Post: