Menu
Coddy logo textTech

The BETWEEN keyword

Part of the Fundamentals section of Coddy's SQL journey — lesson 19 of 72.

As of now, we learned to use bigger > and smaller < to demand a range for a field. But there is another way.

Instead of writing:

WHERE col1 >= 5 AND col1 <= 10

We can write:

WHERE col1 BETWEEN 5 AND 10

The BETWEEN operator is inclusive, meaning it includes the boundary values (in this case, 5 and 10) in the results. This makes your SQL queries cleaner and more readable, especially when dealing with date ranges or numerical intervals.

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>data</strong>: <strong>value</strong>

Fetch all of the records where the value column is between 7 and 13

Cheat sheet

The BETWEEN operator provides a cleaner way to specify ranges instead of using >= and <=:

WHERE col1 BETWEEN 5 AND 10

This is equivalent to:

WHERE col1 >= 5 AND col1 <= 10

The BETWEEN operator is inclusive, meaning it includes the boundary values in the results.

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals