I am new to the SQL, working on this query and found interesting output, please help in understanding why the output is different. Giving literal manager_id
values in NOT IN
clause (query 1) returns records, but if I use the subquery to return same literal values inside the NOT IN
clause (query 2) 0 records are returned.
Thanks in advance
Query 1:
SELECT COUNT(*)
FROM employees
WHERE employee_id NOT IN (
100, 123, 120, 121, 147, 108, 148, 149, 205, 102, 201, 101, 114, 124, 145, 146, 103, 122
);
Result 1:
COUNT(*)
--------
89
Query 2:
SELECT COUNT(*)
FROM employees
WHERE employee_id NOT IN (
SELECT DISTINCT manager_id
FROM employees
);
Result 2:
COUNT(*)
--------
0
Shouldn't it output the same result set?