- 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
MySQL query to display records ordered by DESC while skipping some?
Let us first create a table −
mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.94 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10,'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(1,'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(4,'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(6,'Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(7,'Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(5,'Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(9,'John'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-------+ | Id | Name | +------+-------+ | 10 | Chris | | 1 | David | | 4 | Bob | | 6 | Sam | | 7 | Mike | | 5 | Carol | | 9 | John | +------+-------+ 7 rows in set (0.00 sec)
Following is the query to display records in DESC while skipping some. Here, we are displaying 4 records while skipping 3 −
mysql> select Name from DemoTable order by Id DESC limit 3,4;
This will produce the following output −
+-------+ | Name | +-------+ | Sam | | Carol | | Bob | | David | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to display records ordered by numeric difference?
- How to ORDER BY DESC and display the first 3 records in MySQL?
- MySQL query to select the nth highest value in a column by skipping values
- MySQL query to display only the records that contains single word?
- MySQL query to order records but fix a specific name and display rest of the values (only some) random
- Display records by grouping dates in MySQL
- MySQL query to display the count of distinct records from a column with duplicate records
- MySQL query to subtract date records with week day and display the weekday with records
- Display an error while inserting duplicate records in a MySQL table
- How to display the storage engine while implementing JDBC - MySQL CONNECTION query?
- Exclude some ID records from a list and display rest in MySQL
- MySQL query to display databases sorted by creation date?
- Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query
- Using GROUP BY and COUNT in a single MySQL query to group duplicate records and display corresponding max value
- MySQL query to display records on the basis of conditions IS NULL OR !=1;?

Advertisements