So I'm testing 2 queries and I'm getting different results. I want to correct/patch up my understanding. Here's two generic SQL queries that to my understanding are the same but when executed get different results. Note this is not a question about diff between ANSI and non-ANSI SQL.
Query 1 (using LEFT JOIN
):
SELECT * FROM person p LEFT JOIN person_log pl
ON p.person_id = pl.person_id
WHERE pl.person_id IS NULL
AND p.is_active = 1;
Query 2 (using 2 queries):
SELECT * FROM person
WHERE person.is_active = 1
AND person_id NOT IN (SELECT person_id FROM person_log);
To my understanding, both represent this in venn diagram form. Also, is one more efficient than the other? A query on JOIN
results vs 2 queries?
EDIT: Changed =
to IS
in query 1. Thanks to @Justin Samuel for spotting the =
error that's causing different results!