Reading Room · Module 02
Track 0/9 (0%)
Course completion
Module 02 · Expressions~12 min · 3 worked queries

Row Expressions, CASE & NULL Recovery

Derive clean categorical labels, normalize strings, and substitute fallback values with COALESCE at row evaluation time.

Trace Live in StudioAll Modules
Core Relational Rule
Scalar expressions — CASE, COALESCE, string normalization, arithmetic — evaluate cleanly per tuple without collapsing rows.Module 02 · Expressions · Reading Room

Mental Model

  1. 01.

    Searched CASE expressions evaluate WHEN branches strictly in written order and stop at the first match.

  2. 02.

    COALESCE returns its first non-NULL argument, turning unpredictable missing values into explicit sentinel defaults.

  3. 03.

    String helpers (LOWER, UPPER, LENGTH, TRIM) transform projection values or normalize predicate comparisons.

Frequent Pitfall to Avoid
Putting a broad CASE branch above a specific one, causing the narrow rule to become unreachable.

Interactive Module Lab · Expressions

9. CASE: if/else inside SQL — sql
SELECT name, salary,
CASE
WHEN salary >= 130000 THEN 'Senior'
WHEN salary >= 90000 THEN 'Mid'
ELSE 'Junior'
END AS level
FROM users
ORDER BY salary DESC;
Execution Stages3 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 9. CASE: if/else inside SQL or animate every row moving between stages in Studio.Open 9. CASE: if/else inside SQL in Studio →

Worked Presets in This Module

9. CASE: if/else inside SQL

CASE picks the first matching branch for each row, perfect for turning numbers into labels.

10. Text functions

UPPER, SUBSTR, LENGTH and || (concatenate) are evaluated row by row during SELECT.

11. COALESCE fills in NULLs

COALESCE returns its first non-NULL argument, a clean way to supply defaults.

Navigation

LivePreparation

Client-side workspace · saved locally