Following are the results of my sql queries:
SELECT DISTINCT(department_id)
from employees
ORDER BY department_id;
Result:
DEPARTMENT_ID
10
20
30
40
50
60
70
80
90
100
110
Then:
SELECT department_id
FROM departments
ORDER BY department_id;
DEPARTMENT_ID
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
When I execute the Following Query, I get the result:
SELECT department_id
from departments
where department_id IN (select distinct(department_id) from employees)
ORDER BY department_id;
DEPARTMENT_ID
10
20
30
40
50
60
70
80
90
100
110
However, the following query returns "NO Rows Selected" when I execute the following query:
SELECT department_id
from departments
WHERE department_id NOT IN (select distinct(department_id) from employees)
ORDER BY department_id;
What I was expected was the Id of departments that are not present in Employees table. I feel its a beginner's mistake however i am not able to resolve this issue. Any help would be largely appreciated.