SQLancer
LESSON 8

SQL (Core) - A short note on NULLs

Progress: 0%

A short note on NULLs

In SQL, NULL represents missing, unknown, or unassigned data. Because NULL is not a value but the absence of a value, it requires special comparison techniques.

1. Three-Valued Logic & Comparing NULLs

Standard comparison operators (like = or !=) do not work with NULL because evaluating building = NULL yields UNKNOWN (NULL), not TRUE or FALSE.

-- Correct way to query missing values
SELECT name, role FROM employees WHERE building IS NULL;

-- Correct way to query assigned values
SELECT name, role FROM employees WHERE building IS NOT NULL;

2. Default Values vs. NULL

An alternative to NULL values is providing data-type appropriate default values (like 0 for numbers or empty strings for text). However, if your database must track missing information accurately without skewing statistical averages, NULL is the proper choice.

🗄️ Schema Explorer SELECTABLE

employees
|

🎯 Exercises Checklist:

1. Find the name and role of all employees who have not been assigned to a building
2. Find the names of the buildings that hold no employees
⚡ Practice Console

Data Output

No results. Run query to fetch data.

Current Task Target

5 rows