Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Returning all data from a table
Select some columns
Filtering rows
Logic
11. The BETWEEN operator
Text patterns
To be or NULL to be
A bit of mathematics
Let's practice

Instruction

Good. Now, if you want to find users who are older than 13 and younger than 70, you can of course use the approach in the previous example:

SELECT
  Id,
  Name
FROM User
WHERE Age <= 70
  AND Age >= 13;

But there is also another approach. Take a look:

SELECT
  Id,
  Name
FROM User
WHERE Age BETWEEN 13 AND 70;

We introduced a new keyword BETWEEN. In this case, we look for rows with the age column set to any value between 13 and 70, including these values.

Exercise

Select the Vin, Brand, and Model of all cars that were produced between 1995 and 2005, inclusive.

Stuck? Here's a hint!

Type:

SELECT
  Vin,
  Brand,
  Model
FROM Car
WHERE ProductionYear BETWEEN 1995 AND 2005;