NULL or Empty String in SQL

Level 368 keystrokes

Lists the customers whose phone is missing: IS NULL finds rows with no value at all and = '' finds empty strings, and OR combines both checks, so Alice (NULL) and Bob ('') are returned.

SQL code

1SELECT
-- Returns the name and phone columns
2 name,
3 phone
4FROM
-- Reads from the customers table
5 customers
-- WHERE keeps only rows with a missing phone
6WHERE
-- IS NULL matches no value at all (Alice); phone = NULL would never be true
7 phone IS NULL
-- OR also matches the empty string '' (Bob), which is a value, not NULL
8 OR phone = '';

Output

+-------+-------+
| name  | phone |
+-------+-------+
| Alice | NULL  |
| Bob   |       |
+-------+-------+
2 rows in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • '× 2
  • ,× 1
  • ;× 1
  • =× 1

More SQL examples at level 3

← SQL typing practice