SQL chapters

Chapter 6 of 17

Filtering, comparison and NULL

Try this in our SQLite Compiler →

The idea

WHERE keeps rows for which its condition is true. Comparisons involving NULL generally produce unknown, not true or false; use IS NULL or IS NOT NULL. AND combines requirements and OR allows alternatives. Parentheses make mixed conditions explicit.

Worked example

WITH scores(name, score) AS (VALUES ('Asha', 82), ('Ravi', 60), ('Mina', NULL))
SELECT name FROM scores WHERE score >= 70 OR score IS NULL ORDER BY name;

What to check

Asha and Mina appear. score = NULL would not find Mina. Decide intentionally whether missing scores should be included.

Practice task

Return only students with a known score below 70. Explain why the NULL row does not pass the comparison.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Run your project to see output here.
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on