In SQL, the BETWEEN operator is used to select values within the data range between two values. Among them, "between and" includes boundary values, that is, including both ends; "not between" does not include boundary values.
SQL BETWEEN operator
The BETWEEN operator selects data between two values value within the range. These values can be numeric, text, or dates.
The BETWEEN operator is usually used in conjunction with AND as the WHERE condition of the query result set.
SQL BETWEEN syntax
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
Example:
Data table
+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | Google | https://www.google.cm/ | 1 | USA | | 2 | 淘宝 | https://www.taobao.com/ | 13 | CN | | 3 | PHP中文网 | //m.sbmmt.com/ | 4689 | CN | | 4 | 微博 | http://weibo.com/ | 20 | CN | | 5 | Facebook | https://www.facebook.com/ | 3 | USA | | 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND | +----+---------------+---------------------------+-------+---------+
The following SQL statement selects all websites with alexa between 1 and 20:
SELECT * FROM Websites WHERE alexa BETWEEN 1 AND 20;## Recommended related tutorials: "
Database Video Tutorial", "PHP Tutorial"
The above is the detailed content of Does sql between include both ends?. For more information, please follow other related articles on the PHP Chinese website!