← Back
LESSON 8
SQL (Core) - A short note on NULLs
Prereq: None | Progress: 0%
Course Syllabus
Lesson 0 📖 What is SQL? Lesson 1 📖 SELECT queries 101 Lesson 2 📖 Queries with constraints (Pt. 1) Lesson 3 📖 Queries with constraints (Pt. 2) Lesson 4 📖 Filtering & sorting results Review 1 📖 Simple SELECT Queries Lesson 6 📖 Multi-table queries with JOINs Lesson 7 📖 OUTER JOINs Lesson 8 📖 A short note on NULLs Lesson 9 📖 Queries with expressions Lesson 10 📖 Queries with aggregates (Pt. 1) Lesson 11 📖 Queries with aggregates (Pt. 2) Lesson 12 📖 Order of execution of a Query Lesson 13 📖 Inserting rows Lesson 14 📖 Updating rows Lesson 15 📖 Deleting rows Lesson 16 📖 Creating tables Lesson 17 📖 Altering tables Lesson 18 📖 Dropping tables Lesson 19 📖 Subqueries & Nested Queries Lesson 20 📖 Set Operations Summary 🎓 Course Completion
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
💡 Hint:
Loading hint...
🔑 Solution SQL:
SELECT * FROM movies; Data Output
No results. Run query to fetch data.