
- 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
Implement MySQL LIMIT and OFFSET in a single query stating its difference
The LIMIT tells about how many records you want while OFFSET gives the records from the given position+1. Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (1.33 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.60 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------+ | Name | +--------+ | John | | Chris | | David | | Bob | | Sam | | Mike | | Carol | | Robert | +--------+ 8 rows in set (0.00 sec)
Following is the query to implement MySQL limit offset −
mysql> select *from DemoTable limit 4 offset 3;
Output
This will produce the following output −
+-------+ | Name | +-------+ | Bob | | Sam | | Mike | | Carol | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- Implement multiple COUNT() in a single MySQL query
- Implement SELECT LIKE and CHAR_LENGTH() in a single MySQL query
- Implement multiple LIKE operators in a single MySQL query
- Pagination using MySQL LIMIT, OFFSET?
- Can we implement 'LIKE' and ‘IN’ in a single MySQL query?
- MySQL LIMIT to select a single row
- Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query
- Which rows are returned while using LIMIT with OFFSET in MySQL?
- MySQL UNION SELECT and IN clause in a single query
- Implement Conditional MySQL Query in a stored procedure?
- Count and sort rows with a single MySQL query
- Change multiple columns in a single MySQL query?
- MySQL update multiple records in a single query?
- Insert multiple rows in a single MySQL query
- MySQL query to sort multiple columns together in a single query

Advertisements