Skip to main content
Module 4 · Lesson 1 of 413/57 in the course~12 min
Module lessons (1/4)

Lists and Ranges: IN and BETWEEN

Lesson preview5 hands-on exercises readySQL Course · Module 4 — Practical SQL

Compact filters for matching a set of values or an inclusive range.

What you'll learn in this lesson

  • Replace long chains of OR with IN (val1, val2, ...) for readable discrete lists.
  • Express numeric and temporal inclusive intervals cleanly with BETWEEN a AND b.
  • Avoid the silent trap of NOT IN in the presence of NULL values.

Overview

Writing WHERE department_id = 1 OR department_id = 2 OR department_id = 4 works, but quickly becomes unreadable as the list grows. SQL offers two compact operators designed to express discrete set membership (IN) and continuous range membership (BETWEEN).

Observe in the stepper how the WHERE phase evaluates IN and BETWEEN on each row individually, before any grouping GROUP BY or sorting ORDER BY:

Sections covered in this lesson

  1. 11. Mental Model: Discrete Sets vs Continuous Intervals
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Lab: WHERE in the SQL Pipeline
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 4 — Practical SQL

Unlock "Lists and Ranges: IN and BETWEEN" and the full SQL Course curriculum

Compact filters for matching a set of values or an inclusive range.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.