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
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
| EmpNo | Ename | DeptId | In (D01,D02,D04)? |
|---|---|---|---|
| 101 | Aaliya | D02 | yes |
| 102 | Kritika | D01 | yes |
| 103 | Shabbir | D01 | yes |
| 104 | Gurpreet | D04 | yes |
| 105 | Joseph | D03 | no |
| 106 | Sanya | D02 | yes |
| 107 | Vergese | D01 | yes |
| 108 | Nachaobi | D05 | no |
| 109 | Daribha | D04 | yes |
| 110 | Tanya | D05 | no |
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.