🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – BETWEEN

Filter rows within a numeric or date range using the BETWEEN operator.

The BETWEEN operator filters rows where a column value falls within a defined range — inclusive of both endpoints. WHERE score BETWEEN 75 AND 90 includes students with exactly 75, exactly 90, and everything in between. This is equivalent to WHERE score >= 75 AND score <= 90, but cleaner and more expressive.

BETWEEN works equally well on numbers, dates, and even strings. A date range query like WHERE enroll_date BETWEEN '2024-01-01' AND '2024-03-31' is a classic pattern for quarterly reporting.

BETWEEN is always inclusive

-- Number range
WHERE score BETWEEN 80 AND 95

-- Date range (quarterly)
WHERE enroll_date BETWEEN '2024-01-01' AND '2024-03-31'

-- Exclude range: NOT BETWEEN
WHERE price NOT BETWEEN 1000 AND 5000

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • BETWEEN is inclusive on both ends
  • Equivalent to column >= low AND column <= high
  • Works on numbers, dates, and strings (alphabetical for strings)
  • NOT BETWEEN excludes the range instead

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.