Contents
SQL BETWEEN Operator: Main Tips
- The BETWEEN operator selects certain range values. The values could be text, dates or numbers.
- The BETWEEN operator can show a different result in different databases.
Syntax of SQL BETWEEN Operator
Selects values within a range.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
Demo Database
This is demo example from the "Orders" table in the database:
ID | Name | Count | Price | Date |
---|---|---|---|---|
1 | Apple | 120 | 11.9 | 2017-08-18 |
2 | Milk | 50 | 9.1 | 2016-12-19 |
3 | Bread | 60 | 15.4 | 2017-06-21 |
3 | Water | 150 | 12.3 | 2017-07-10 |
3 | Chocolate | 85 | 21.9 | 2016-12-25 |
SQL BETWEEN Operator: Examples
In this example, we select all orders with a price being BETWEEN 10 and 15:
In this example, we select all orders with a price being NOT BETWEEN 10 and 15:
In this example, we select all orders with a price being BETWEEN 10 and 15, but products with an OrderID of 1 or 2 are not be displayed:
SELECT * FROM Orders
WHERE (Price BETWEEN 10 AND 15)
AND NOT ID IN (1,2);
In this example, we select all orders with an OrderName beginning with any of the letter BETWEEN 'A' and 'C':
In this example, we select all products with an OrderName beginning with any of the letter NOT BETWEEN 'A' and 'C':
In this example, we select all orders with an OrderName BETWEEN 'Apple' and 'Bread':
SELECT * FROM Orders
WHERE Name BETWEEN 'Apple' AND 'Bread'
ORDER BY Name;
In this example, we select all orders with an OrderName NOT BETWEEN 'Apple' and 'Bread':
SELECT * FROM Orders
WHERE Name NOT BETWEEN 'Apple' AND 'Bread'
ORDER BY Name;
In this example, we select orders when an OrderDate is BETWEEN '2016-07-05' and '2017-07-10':
SELECT * FROM Orders
WHERE Date BETWEEN '2016-07-05' AND '2017-07-10';