Skip to content
Worked Examples · Example 9.8

Q.The following query selects details of all the employees except those working in department number D01 or D02.

Yanam CbseNCERTSubjective· 2mImportance★★★★★
16% · 15/95 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

NOT IN excludes rows whose column value is in the given list. Run against the chapter's EMPLOYEE table (Table 9.8), WHERE DeptId NOT IN ('D01','D02') returns the 5 employees who are in neither department.

The query

SELECT *
FROM EMPLOYEE
WHERE DeptId NOT IN ('D01', 'D02');

This is equivalent to WHERE DeptId != 'D01' AND DeptId != 'D02' — De Morgan's law turns "not (A or B)" into "(not A) and (not B)".

Checking every row of Table 9.8

EmpNoEnameDeptIdExcluded (D01/D02)?Selected?
101AaliyaD02yesno
102KritikaD01yesno
103ShabbirD01yesno
104GurpreetD04noyes
105JosephD03noyes
106SanyaD02yesno
107VergeseD01yesno
108NachaobiD05noyes
109DaribhaD04noyes
110TanyaD05noyes

Output (5 rows):

+-------+----------+--------+-------+--------+
| EmpNo | Ename    | Salary | Bonus | DeptId |
+-------+----------+--------+-------+--------+
|   104 | Gurpreet |  19000 |   565 | D04    |
|   105 | Joseph   |  34000 |   875 | D03    |
|   108 | Nachaobi |  29000 |  NULL | D05    |
|   109 | Daribha  |  42000 |  NULL | D04    | …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.