Q.The following query selects names of all employees who have been given a bonus (i.e., Bonus is not null) and works in the department D01.
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 →The query uses WHERE with two conditions — Bonus IS NOT NULL and DeptId = 'D01' — connected by AND. On the real EMPLOYEE table (Table 9.8) this returns Kritika and Shabbir.
The real EMPLOYEE table (Table 9.8)
| EmpNo | Ename | Salary | Bonus | DeptId |
|---|---|---|---|---|
| 101 | Aaliya | 10000 | 234 | D02 |
| 102 | Kritika | 60000 | 123 | D01 |
| 103 | Shabbir | 45000 | 566 | D01 |
| 104 | Gurpreet | 19000 | 565 | D04 |
| 105 | Joseph | 34000 | 875 | D03 |
| 106 | Sanya | 48000 | 695 | D02 |
| 107 | Vergese | 15000 | NULL | D01 |
| 108 | Nachaobi | 29000 | NULL | D05 |
| 109 | Daribha | 42000 | NULL | D04 |
| 110 | Tanya | 50000 | 467 | D05 |
The core idea here is filtering with multiple conditions. SQL's WHERE clause lets you specify which rows to keep; when every condition must be true at once, you combine them with AND.
For "Bonus is not null", remember NULL is not a value — it's the absence of one, so you cannot use = NULL or != NULL. SQL provides the special operators IS NULL and IS NOT NULL.
A common mistake is writing Bonus != NULL or Bonus = NULL. Neither works in SQL because NULL comparisons always yield unknown, not true or false. Always use IS NULL or IS NOT NULL.
mysql> SELECT EName FROM EMPLOYEE
-> WHERE Bonus IS NOT NULL
-> AND DeptId = 'D01';
Key lines explained:
SELECT EName— we only need the employee names, not other columns.FROM EMPLOYEE— the chapter's own EMPLOYEE table (Table 9.8). …
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.