- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the alternative of BETWEEN clause to fetch values between a range in MySQL?
To avoid using the BETWEEN clause, you can use the AND to fetch the values between a range. Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(85); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable −
This will produce the following output −
+--------+ | Number | +--------+ | 10 | | 20 | | 60 | | 100 | | 90 | | 85 | +--------+ 6 rows in set (0.00 sec)
Following is the query to fetch values between a range without using the BETWEEN clause −
mysql> select *from DemoTable where 15 <=Number and Number <= 80;
This will produce the following output −
+--------+ | Number | +--------+ | 20 | | 60 | +--------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL date comparison to fetch dates between a given range?
- Fetch a value between different values in MySQL
- Can we fetch multiple values with MySQL WHERE Clause?
- Fetch alternative even values from a JavaScript array?
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- MongoDB query to fetch elements between a range excluding both the numbers used to set range?
- MySQL query to fetch records from a range of months?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- How to find a value between range in MySQL?
- Fetch data between two rows in MySQL?
- MySQL automatic string to integer casting in WHERE clause to fetch a specific id
- What is the use of ORDER BY clause in MySQL?
- MySQL query to fetch multiple least values?
- MySQL query to select all data between range of two dates?
- How to select particular range of values in a MySQL table?

Advertisements