M
PRO
Mate
asked

Expert
Abhay Jajodia answered
In SQL, when you use the NOT BETWEEN operator, it will filter out all values that fall within the given range, including the start and end numbers.
So, in the following example:
SELECT first_name, country, age
FROM Customers
WHERE age NOT BETWEEN 22 AND 28;This query is filtering out customers whose ages are 22 through 28, not 23 through 27.
By using NOT BETWEEN 22 AND 28, it means ages 22, 23, 24, 25, 26, 27, and 28 will be excluded.
If your intention is to exclude just from 22 through 27, you'd phrase it like:
SELECT first_name, country, age
FROM Customers
WHERE age NOT BETWEEN 22 AND 27;If you meant to exclude up to but not including 28, then the range should definitely stop at 27 for your query.
Hope this helps clear things up! Let me know if you have more questions.
SQL
This question was asked as part of the Learn SQL Basics course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer