Skip to content
Worked Examples · Example 9.11

Q.The following query selects details of all those employees who have not been given a bonus. This implies that the bonus column will be blank.

Uttar Pradesh UpmspTextbookSubjective· 2mImportance★★★★★
22% · 21/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 bonus column is blank" means the column contains NULL. NULL is not zero and not an empty string — it is the absence of a value, and it can only be tested with the IS NULL operator:

SELECT * FROM EMPLOYEE WHERE Bonus IS NULL;

Concept understanding — what NULL really is

Value in the columnMeaningTest that finds it
0a bonus of zero rupees was givenBonus = 0
'' (empty string)an empty text value was storedBonus = ''
NULLno bonus value exists at all — unknown / not applicableBonus IS NULL

The three are genuinely different. An employee with Bonus = 0 was processed and awarded nothing; an employee with Bonus = NULL was never assigned a bonus at all. The question says the column is blank, which is the NULL case.

Important

SQL uses three-valued logic: TRUE, FALSE and UNKNOWN. Any arithmetic or comparison involving NULL yields UNKNOWN, and a WHERE clause only keeps rows for which the condition is TRUE. So Bonus = NULL is UNKNOWN for every single row — including the NULL ones — and the query returns nothing at all. It is not an error; it silently returns an empty set, which is far more dangerous.

The real EMPLOYEE table (Table 9.8)

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

The query

mysql> SELECT * FROM EMPLOYEE
    -> WHERE Bonus IS NULL;

Output

+-------+----------+--------+-------+--------+
| EmpNo | Ename    | Salary | Bonus | DeptId |
+-------+----------+--------+-------+--------+
|   107 | Vergese  |  15000 |  NULL | D01    |
|   108 | Nachaobi |  29000 |  NULL | D05    |
|   109 | Daribha  |  42000 |  NULL | D04    |
+-------+----------+--------+-------+--------+
3 rows in set (0.00 sec)

Row-by-row evaluation

EmployeeBonusBonus IS NULLSelected?
Aaliya234FALSEno
Kritika123FALSEno
Shabbir566FALSEno
Gurpreet565FALSEno
Joseph875FALSEno
Sanya695FALSEno
VergeseNULLTRUEyes

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.