MySQL - Between
The BETWEEN operator is used in a WHERE clause to select a range of data between two values. The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.
SQL BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
MySQL Between Example
The "Persons" table:
| ID | First Name | Last Name | Address |
| 1 | Putu | Sanjaya | Denpasar |
| 2 | Made | Sanjaya | Gianyar |
| 3 | Haru | Sanjaya | Sanur |
Now we want to select the persons with a first name alphabetically between "Komang" and "Haru" from the table above.
We use the following SELECT statement:
SELECT * FROM Persons
WHERE FirstName
BETWEEN 'Putu' AND 'Haru'
The result-set will look like this:
| ID | First Name | Last Name | Address |
| 3 | Haru | Sanjaya | Sanur |