Skip to content
Worked Examples · Example 9.12

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.

Yanam BieapTextbookSubjective· 2mImportance★★★★★
24% · 23/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 →

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)

EmpNoEnameSalaryBonusDeptId
101Aaliya10000234D02
102Kritika60000123D01
103Shabbir45000566D01
104Gurpreet19000565D04
105Joseph34000875D03
106Sanya48000695D02
107Vergese15000NULLD01
108Nachaobi29000NULLD05
109Daribha42000NULLD04
110Tanya50000467D05

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.

Watch out

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.