- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Fetch a value between different values in MySQL
Use MySQL BETWEEN to fetch a value between different values. Let us first create a table −
mysql> create table DemoTable1473 -> ( -> EmployeeCode varchar(20) -> ); Query OK, 0 rows affected (0.47 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1473 values('EMP_120'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1473 values('EMP_125'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1473 values('EMP_30'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1473 values('EMP_130'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1473;
This will produce the following output −
+--------------+ | EmployeeCode | +--------------+ | EMP_120 | | EMP_125 | | EMP_30 | | EMP_130 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to fetch a value between different values −
mysql> select * from DemoTable1473 -> where EmployeeCode between 'EMP_124' and 'EMP_129';
This will produce the following output −
+--------------+ | EmployeeCode | +--------------+ | EMP_125 | +--------------+ 1 row in set (0.00 sec)
- Related Articles
- What is the alternative of BETWEEN clause to fetch values between a range in MySQL?
- Get a random value between two values in MySQL?
- Fetch a specific column value (name) in MySQL
- MySQL query to fetch the maximum corresponding value from duplicate column values
- Select a specific value between two column values in MySQL?
- Fetch the maximum value from a MySQL column?
- MySQL query to fetch multiple least values?
- Using Aggregate function to fetch values from different tables in SAP
- Get the time difference between values in different columns with MySQL
- Use LIKE % to fetch multiple values in a single MySQL query
- Fetch data between two rows in MySQL?
- Fetch records from comma separated values using MySQL IN()?
- MySQL db query to fetch records from comma separate values on the basis of a specific value
- How to join tables and fetch values from a MySQL database?
- MySQL query to fetch the maximum cumulative value

Advertisements