Home  >  Article  >  Backend Development  >  How to use the SQL BETWEEN operator

How to use the SQL BETWEEN operator

jacklove
jackloveOriginal
2018-05-08 10:08:052842browse

SQL BETWEEN Operator is very important in the operation of PHP database. This article will explain its related operations.

The BETWEEN operator is used in the WHERE clause to select a data range between two values.

BETWEEN Operator

Operator BETWEEN ... AND will select a range of data between two values. These values ​​can be numeric, text, or dates.

SQL BETWEEN syntax

SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2

BETWEEN operator example

If you want to display in alphabetical order between "Adams" (inclusive) and "Carter" (exclusive) Please use the following SQL:

SELECT * FROM Persons
WHERE LastNameBETWEEN 'Adams' AND 'Carter'

Important: Different databases handle the BETWEEN...AND operator differently. Some databases will list people between "Adams" and "Carter" but not including "Adams" and "Carter"; some databases will list people between "Adams" and "Carter" and including "Adams" and "Carter"; other databases will list people between "Adams" and "Carter", including "Adams" but not "Carter".

So, please check how your database handles the BETWEEN....AND operator!

Example 2

If you need to use the above example to display people outside the range, please use the NOT operator:

SELECT * FROM Persons
WHERE LastNameNOT BETWEEN 'Adams' AND 'Carter'

This article has the following operations on the SQL BETWEEN operator To understand, for more learning materials, please pay attention to the php Chinese website to view.

Related recommendations:

How to use the SQL IN operator

Explanation of SQL wildcard related knowledge

Explanation on SQL LIKE operator

The above is the detailed content of How to use the SQL BETWEEN operator. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn