
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Fetch data between two rows in MySQL?
To fetch data between two rows, use the concept of LIMIT. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(10) ); Query OK, 0 rows affected (0.22 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.05 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Larry | | 2 | Robert | | 3 | Chris | | 4 | David | | 5 | Bob | | 6 | Sam | | 7 | Mike | | 8 | Carol | | 9 | John | +----+--------+ 9 rows in set (0.00 sec)
Following is the query to fetch data between two rows −
mysql> select *from DemoTable limit 2,3;
This will produce the following output -
+----+-------+ | Id | Name | +----+-------+ | 3 | Chris | | 4 | David | | 5 | Bob | +----+-------+ 3 rows in set (0.00 sec)
- Related Articles
- Python Pandas – Fetch the Common rows between two DataFrames with concat()
- Fetch random rows from a table with MySQL
- Fetch rows where first character is not alphanumeric in MySQL?
- Swap data between two columns in MySQL?
- How to fetch only N rows at a time in MySQL?
- How to fetch random rows in MySQL with comma separated values?
- Python Pandas – Find the common rows between two Data Frames
- Fetch a value between different values in MySQL
- MySQL rows concatenation to fetch maximum corresponding value from duplicate IDs?
- Fetch rows where a field value is less than 5 chars in MySQL?
- Fetch similar ID records from two tables in MySQL
- MySQL select query to fetch data with null value?
- Query MySQL table and fetch rows posted before the last 3 days?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- How to find the correlation coefficient between rows of two data frames in R?

Advertisements