How to use the SQL BETWEEN operator

jacklove
Release: 2023-03-25 15:26:02
Original
2847 people have browsed it

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
Copy after login

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'
Copy after login

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'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!