

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we get the sorted MySQL output?
We know that MySQL SELECT command is used to fetch data from a MySQL table. When you select rows, the MySQL server is free to return them in any order, unless you instruct it otherwise by saying how to sort the result. But, we can sort a result set by adding an ORDER BY clause that names the column or columns which you want to sort.
Syntax
Select column1, column2,…,columN From table_name ORDER BY column1[column2,…];
Example
In the example below, MySQL returns the result set sorted on the basis of column ‘Name’;
mysql> Select Id, Name, Address from Student ORDER BY Subject; +------+---------+---------+ | Id | Name | Address | +------+---------+---------+ | 15 | Harshit | Delhi | | 1 | Gaurav | Delhi | | 17 | Raman | Shimla | | 2 | Aarav | Mumbai | +------+---------+---------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- How can we get sorted output based on multiple columns?
- How can we get an idea about the server performance from the output of MySQL?
- In MySQL, how we can get the total value by category in one output row?
- How can we get the summary output of a column in MySQL result set itself?
- How can we sort MySQL output in descending order?
- How can we sort MySQL output in ascending order?
- How can we get the metadata of MySQL events?
- How can we get the structure of a MySQL view as we can get the structure of a MySQL table?
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- How can we specify the number of records to be returned in MySQL output?
- How can I get the output of multiple MySQL tables from a single query?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How can we fetch a particular row as output from a MySQL table?
- How can we get the list of MySQL server-side help categories?
- How can we get all the unique rows in MySQL result set?
Advertisements