SQL Practice Logo

SQLPractice Online

Range & Interval Filtering: Concept

Module: Advanced Filtering

Range filtering selects data within boundaries using BETWEEN, comparison operators, and INTERVAL for relative date calculations.

**Date Ranges:**

BETWEEN for inclusive ranges:

WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31'

Comparison operators:

WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01'

**INTERVAL (PostgreSQL):**

Relative date calculations:

WHERE order_date >= CURRENT_DATE - INTERVAL '30 days'

WHERE created_at >= NOW() - INTERVAL '1 hour'

**Numeric Ranges:**

WHERE price BETWEEN 10 AND 100

WHERE quantity >= 5 AND quantity <= 50

**Performance:**

- Index date/numeric columns used in ranges

- Use >= and < for date ranges (not BETWEEN)

- Avoid functions on indexed columns

Essential for analytics, reporting, and time-series data. Used daily by data analysts and backend engineers.

Range filtering powers time-based reports: last 30 days sales, orders between dates, products in price range, events within time window.