NULL Handling · Question 8 · Medium

NULL Handling question 8

Table Staff:
id | name | dept | bonus
1 | Anita | HR | 5000
2 | Bhavesh | IT | NULL
3 | Charu | IT | 8000
4 | Deepak | Sales | NULL
5 | Esha | HR | 3000

The WHERE clause joins two conditions with OR. Which names are returned?

SELECT name
FROM Staff
WHERE bonus > 4000 OR dept = 'IT'
ORDER BY name;
  1. Anita; Charu
  2. Anita; Bhavesh; Charu; Deepak
  3. Anita; Bhavesh; Charu
  4. Bhavesh; Charu
Answer and explanation

Answer: C. Anita; Bhavesh; Charu

Explanation: Anita passes on bonus > 4000 and Charu passes on both parts. For Bhavesh, bonus > 4000 is UNKNOWN but dept = 'IT' is TRUE, and UNKNOWN OR TRUE is TRUE. Deepak gets UNKNOWN OR FALSE = UNKNOWN and is dropped.

Previous: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |… · Next: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…

Practise null handling

Try a fresh set of null handling questions with an explanation after every answer, free and without signing up: NULL Handling practice. Or sit a full placement mock test.

More null handling questions

More sql practice

SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge