- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of ORDER BY clause in MySQL?
152 Lectures 16 hours
87 Lectures 5.5 hours
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.
- How to use union and order by clause in MySQL?
- How can we use ORDER BY clause while calculating the Date?
- While using the ROLLUP modifier, is it possible to use a MySQL ORDER BY clause to sort the result?
- What is the purpose of ORDER BY columnname*1 in MySQL?
- What is the significance of using multiple columns in MySQL GROUP BY clause?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- Sort by order of values in a MySQL select statement IN clause?
- How can we create the MySQL view with ORDER BY clause?
- How can I use RAND() function in an ORDER BY clause to shuffle MySQL set of rows?
- What is the benefit of using MySQL SUM() function with GROUP BY clause?
- How to order or choose rows 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?
- Can we use ORDER BY NULL in MySQL?
- What is the importance of the order of Columns in the SET clause of UPDATE statement? Will it make big difference in result set returned by MySQL?