Know Your NULLs

1 min read Original article ↗

These questions were inspired by the talk WAT that makes fun of some Javascript and Ruby "features". I've been reading The Art of Postgresql and thought SQL NULLs deserved a similar treatment. Please enjoy this quiz that sheds some light on the best NULL semantics in SQL. All examples were run in Postgres. Other RDBMSs may differ slightly.

employees
+----+-------+------------+
| id | name  | manager_id |
+----+-------+------------+
| 1  | Alice | NULL       |
| 2  | Bob   | 1          |
| 3  | Cara  | 2          |
| 4  | Dana  | NULL       |
+----+-------+------------+
SELECT id, name FROM employees WHERE manager_id != 1;