Hi everybody,
I'm a bit lost here on my SQL 2008.
I have two tables: tbl_transaction and tbl_devicehistory (1:n). The relation is described in the first query.
I want to find all entries in tbl_transaction, that don't have a corresponding entity in tbl_devicehistory.
The first query works as expected (and yields the correct results)
SELECT t.* FROM tbl_transaction t LEFT JOIN tbl_devicehistory h ON t.id_transaction = h.id_transaction WHERE h.id_history IS NULL
But the second does not (yields no results at all):
SELECT t.* FROM tbl_transaction t WHERE t.id_transaction NOT IN (SELECT DISTINCT(h.id_transaction) FROM tbl_devicehistory h)
I don't have a clue why this does not work. In my opinion the second query should yield the same result as the first, shouldn't it?
Where am I wrong? I know how to get the results, but
why is the second query not working?
Cheers,
Sandra