Reading Room · Module 01
Track 0/9 (0%)
Course completion
Module 01 · Foundations~18 min · 8 worked queries

Logical Clause Order, Filtering & Pagination

SQL executes top-to-bottom in logical order — FROM first, then WHERE, SELECT, DISTINCT, ORDER BY, and LIMIT — regardless of how clauses are written.

Trace Live in StudioAll Modules
Core Relational Rule
Write SELECT first, but read execution starting at FROM. Aliases created in SELECT do not exist yet when WHERE runs, and NULL fails every equality check (= and !=) unless tested with IS NULL.Module 01 · Foundations · Reading Room

Mental Model

  1. 01.

    FROM loads the source relation into working row memory before any column projection happens.

  2. 02.

    WHERE tests every row independently against a three-valued predicate (TRUE, FALSE, UNKNOWN): only TRUE advances.

  3. 03.

    AND binds tighter than OR, so compound filters without parentheses frequently admit unintended rows.

  4. 04.

    ORDER BY and LIMIT run near the end of the pipeline, shaping a sequence that already survived filtering and projection.

Frequent Pitfall to Avoid
Assuming column != 'Engineering' returns rows with NULL departments, or referencing a SELECT alias directly inside WHERE.

Interactive Module Lab · Basics

2. Filtering with WHERE — sql
SELECT name, role, salary, country
FROM users
WHERE salary >= 85000
ORDER BY salary DESC;
Execution Stages4 steps
Stage 01 · FROM

SOURCE: USERS

10 in → 10 out

Scanned 10 rows from table 'users'.

#idnamedepartment_idrolesalarystate
11Alice Smith1Software Engineer95,000keep
22Bob Jones2Product Manager110,000keep
33Charlie Lee1Software Engineer88,000keep
44Diana Prince3UX Designer76,000keep
55Evan Wright2Data Analyst82,000keep
66Fiona Gallagher1Tech Lead135,000keep
77George ClarkNULLIntern42,000keep
88Hannah Abbott2Scrum Master89,000keep
Inspect each evaluated clause in 2. Filtering with WHERE or animate every row moving between stages in Studio.Open 2. Filtering with WHERE in Studio →

Worked Presets in This Module

1. Pick columns and compute new ones

FROM reads the table first; SELECT only shapes the columns afterwards. Aliases are created at the very end.

2. Filtering with WHERE

WHERE tests every row and drops the ones that are not TRUE, then ORDER BY sorts what is left.

3. AND binds tighter than OR

Without parentheses this means: USA, or (UK and salary over 100k). Watch which rows survive.

4. IN, BETWEEN and LIKE

Three shortcuts for common tests: a list of values, an inclusive range, and a text pattern.

5. NULL is not equal to anything

George has no department. "department_id != 1" is unknown for him, and WHERE only keeps TRUE, so he vanishes.

6. Finding NULLs with IS NULL

Use IS NULL (never = NULL) to find missing values.

7. DISTINCT removes repeated rows

DISTINCT runs after SELECT, so it compares the final column values.

8. ORDER BY, LIMIT and OFFSET

Sort first, skip two rows, then take three. LIMIT is always the last step.

Navigation

LivePreparation

Client-side workspace · saved locally