
- 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
What is the use of ORDER BY clause in MySQL?
MySQL ORDER BY clause is used to specify the sorting on the result of a query. The keyword ORDER BY must be followed by the name of the column on which we want to sort. For example, we want to sort the following table named ‘ratelist’ on the basis of column ‘price’ −
mysql> Select * from ratelist; +----+------+-------+ | Sr | Item | Price | +----+------+-------+ | 1 | A | 502 | | 2 | B | 630 | | 3 | C | 1005 | | 4 | h | 850 | | 5 | T | 250 | +----+------+-------+ 5 rows in set (0.05 sec)
The sorting can be done with the help of ORDER BY clause as follows −
mysql> Select * from ratelist ORDER BY Price; +----+------+-------+ | Sr | Item | Price | +----+------+-------+ | 5 | T | 250 | | 1 | A | 502 | | 2 | B | 630 | | 4 | h | 850 | | 3 | C | 1005 | +----+------+-------+ 5 rows in set (0.01 sec)
The query above sorted the table on the basis of price in default sorting order i.e. ascending.
- Related Articles
- How to use union and order by clause in MySQL?
- How can I use RAND() function in an ORDER BY clause to shuffle MySQL set of rows?
- Sort by order of values in a MySQL select statement IN clause?
- While using the ROLLUP modifier, is it possible to use a MySQL ORDER BY clause to sort the result?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- How can we use ORDER BY clause while calculating the Date?
- How can we create the MySQL view with ORDER BY clause?
- How to order or choose rows in MySQL GROUP BY clause?
- What is the significance of using multiple columns in MySQL GROUP BY clause?
- Get the returned record set ordered by (ORDER BY) position in MySQL 'IN' clause
- How to select MySQL rows in the order of IN clause?
- What is the purpose of ORDER BY columnname*1 in MySQL?
- Get the returned record set order in MySQL IN clause?
- Can we use ORDER BY NULL in MySQL?
- What is the benefit of using MySQL SUM() function with GROUP BY clause?

Advertisements