- 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 order from a different starting value?
Let us first create a table −
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(30) ); Query OK, 0 rows affected (0.74 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(ClientName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientName) values('Robert'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ClientName) values('Bob'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(ClientName) values('Carol'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ClientName) values('Sam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(ClientName) values('Mike'); 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 −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | | 5 | Bob | | 6 | Carol | | 7 | Sam | | 8 | Mike | +----------+------------+ 8 rows in set (0.00 sec)
Following is the query of MySQL Order from a starting value −
mysql> select *from DemoTable order by ClientId < 5,ClientId;
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 5 | Bob | | 6 | Carol | | 7 | Sam | | 8 | Mike | | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | +----------+------------+ 8 rows in set (0.00 sec)
- Related Articles
- MySQL order by from highest to lowest value?
- Get MySQL maximum value from 3 different columns?
- Update only a single value from a MySQL table where select from same table ordered in descending order?
- How to order by the highest value from two columns in MySQL?
- Fetch a value between different values in MySQL
- Display two different columns from two different tables with ORDER BY?
- Order randomly in MySQL with a random value column?
- Set a certain value first with MySQL ORDER BY?
- Is there a default ORDER BY value in MySQL?
- Order by desc except a single value in MySQL
- Selecting a value in custom order from another column in a MySQL table with a single query
- MySQL ORDER BY with custom field value
- How to extract substring from a sting starting at a particular position in MySQL?
- ORDER BY specific field value first in MySQL
- MySQL query to first set negative value in descending order and then positive value in ascending order

Advertisements