Press "Enter" to skip to content

mysql-between

MySQL BETWEEN Operator

The BETWEEN operator used to retrieve values within a range in to compare . We frequently use the BETWEEN operator in the WHERE clause of the SELECT, INSERT, UPDATE, and DELETE statements.

SYNTAX


SELECT * FROM table_name
WHERE COLUMN NAME
BETWEEN begin_expr AND end_expr

Table structure Used for Example explanation

+————-+———-+
| Field | Type |
+————-+———-+
| ID | int(11) |
| Name | char(35) |
| CountryCode | char(3) |
| District | char(20) |
| Population | int(11) |
+————-+———-+

Example for MYSQL Limit

select * from city where population between 300000 and 2700000;

Output of Above Example

+—-+————-+————-+—————+————+
| ID | Name | CountryCode | District | Population |
+—-+————-+————-+—————+————+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
| 6 | Rotterdam | NLD | Zuid-Holland | 593321 |
| 7 | Haag | NLD | Zuid-Holland | 440900 |
| 35 | Alger | DZA | Alger | 2168000 |
| 36 | Oran | DZA | Oran | 609823 |
| 37 | Constantine | DZA | Constantine | 443727 |
+—-+————-+————-+—————+————+
7 rows in set (0.00 sec)