SQL BETWEEN

BETWEEN filters values inside a range, including both ends. It works on numbers, text and dates.

With timestamps, be careful: BETWEEN '2025-03-01' AND '2025-03-31' stops at midnight at the start of 31 March. For timestamps, prefer >= start AND < next day.

Syntax

WHERE column BETWEEN low AND high

Try it yourself

Run the example below on a real PostgreSQL database, then change it and run it again. Nothing to install, no sign-up.

between.sql · PostgreSQL
Loading editor…

Examples

1. Number range

SELECT name, price FROM products WHERE price BETWEEN 20 AND 40;

Includes products costing exactly 20 or 40.

2. Date range

SELECT id, order_date FROM orders WHERE order_date BETWEEN '2025-03-01' AND '2025-03-31';

Works perfectly for DATE columns.

Common mistakes

  • Putting the larger value first: BETWEEN 40 AND 20 returns nothing.
  • Using BETWEEN on timestamps and silently losing the last day.

Practice: test yourself

This challenge is from our interactive course. Write the query and press Check answer.

Challenge · 20 pts

Return the id and order_date of orders placed in March 2025 (1 March to 31 March inclusive).

challenge.sql · PostgreSQL
Loading editor…

FAQ

Is BETWEEN inclusive?

Yes. Both the low and the high value are included.

Learn SQL step by step

65 hands-on exercises, streaks, a leaderboard and a certificate.

Start free →