AI Hints
Homeโ€บSQL Tutorialโ€บRanges, Patterns and Missing Values
SQL ยท Lesson 13 of 126

Ranges with BETWEEN

From this to that.

โฑ 2 min readโ–ถ Video at 18:50๐ŸŽ“ Free
Watch this lesson in the SQL courseWatch on YouTube โ†—Full SQL course

Customers often say, I want to spend between fifteen and twenty dollars. You could write price greater than or equal to fifteen, and price less than or equal to twenty. But SQL has a shortcut that reads just like English.

Ranges with BETWEEN
From the video: Ranges with BETWEEN
  • Spend between $15 and $20
  • Two tests would work
  • A shortcut that reads like English

BETWEEN

Between takes a low value, the word and, and a high value. It includes both ends. So a book at exactly fifteen, or exactly twenty, would be kept. Run it. Seven books fall in the fifteen to twenty dollar range.

query.sqlsql
SELECT title, price
FROM books
WHERE price BETWEEN 15 AND 20;
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          title           โ”‚ price โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ A Short History of Bread โ”‚ 19.99 โ”‚
โ”‚ Running on Empty         โ”‚ 15.99 โ”‚
โ”‚ Dragons of Ember Bay     โ”‚ 17.99 โ”‚
โ”‚ The Map Maker's Daughter โ”‚ 18.99 โ”‚
โ”‚ Crown of Ash             โ”‚ 16.99 โ”‚
โ”‚ Startup Stories          โ”‚ 19.99 โ”‚
โ”‚ The Glass Forest         โ”‚ 18.49 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Ranges of dates

Between works on dates too. In this database, dates are written as year, month, and day, like twenty twenty five, dash twelve, dash zero one. That format sorts correctly, so between works perfectly. Run it. There were one hundred and four orders in December twenty twenty five.

query.sqlsql
SELECT COUNT(*)
FROM orders
WHERE order_date BETWEEN '2025-12-01' AND '2025-12-31';
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ COUNT(*) โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 104      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

Between is a neat way to ask for a range, including both ends, for numbers or dates. Next, how to search inside text, when you only know part of a word.

Key takeaways
  • BETWEEN low AND high
  • Both ends included
  • Works on dates too
Next up: Patterns with LIKE โ€” search inside text