I'm using Oracle, and I have next query:
SELECT count(*) FROM table1;
SELECT count(*) FROM table2 WHERE attr1 IN (SELECT attr1 FROM table1);
SELECT count(*) FROM table1 WHERE attr1 NOT IN
(SELECT attr1 FROM table2 WHERE attr1 IN (SELECT attr1 FROM table1));
11443 (total - 10489)
You are counting records in
attr1 of which also exists in
table1. That doesn't tell us anything about the records in
table2 that have no such match. Could be 1 record, could be a million records all with different
attr1, could be a million records all with the same
attr1, etc. So there is no math to tell us what your last query should result in.
... Or there is something about the two tables and
attr1 that you haven't told us.