Skip to content
Worked Examples · Example 9.7

Q.The following query selects details of all the employees who work in the departments having deptid D01, D02 or D04.

Puducherry CbseNCERTSubjective· 2mImportance★★★★★
14% · 13/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 →

IN tests set membership — it replaces a chain of OR conditions on the same column. Run against Table 9.8, WHERE DeptId IN ('D01','D02','D04') returns 7 of the 10 employees.

Two equivalent forms

-- Using OR
SELECT * FROM EMPLOYEE
WHERE DeptId = 'D01' OR DeptId = 'D02' OR DeptId = 'D04';

-- Using IN (cleaner, same result)
SELECT * FROM EMPLOYEE
WHERE DeptId IN ('D01', 'D02', 'D04');

Checking every row of Table 9.8

EmpNoEnameDeptIdIn (D01,D02,D04)?
101AaliyaD02yes
102KritikaD01yes
103ShabbirD01yes
104GurpreetD04yes
105JosephD03no
106SanyaD02yes
107VergeseD01yes
108NachaobiD05no
109DaribhaD04yes
110TanyaD05no

Output (7 rows):

+-------+----------+--------+-------+--------+
| EmpNo | Ename    | Salary | Bonus | DeptId |
+-------+----------+--------+-------+--------+
|   101 | Aaliya   |  10000 |   234 | D02    |
|   102 | Kritika  |  60000 |   123 | D01    |
|   103 | Shabbir  |  45000 |   566 | D01    | …

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.