In my database I have a table which holds all Files
This table has several dependencies (Let's name them: FilesDep1, FilesDep2, FilesDep3, FilesDep4, FilesDep5)
The files table holds over 20000 records and I need to filter out the files that are not used by any of the five dependencies.
So I used union on all FileId's from the FilesDep1
as
select Id from [Files] where Id not in
(
select FileId from [FilesDep1]
union
select FileId from [FilesDep2]
union
select FileId from [FilesDep3]
union
select FileId from [FilesDep4]
union
select FileId from [FilesDep5]
)
The amount given by all the unions is 1997. So I expect to get 18000+ records from this query, However... it returns 0?
I would like to know what causes this behaviour?
If I change the not in
to in
, it does show the 1997 records given by the unionquery...
ps. Please do not respond to the naming of tables, or the fact that i'm using union for this query instead of inner joins or something else. This question is about why the union query does not work as expected.