Home  >  Article  >  Database  >  How can we get the sorted MySQL output?

How can we get the sorted MySQL output?

WBOY
WBOYforward
2023-08-31 16:13:07559browse

How can we get the sorted MySQL output?

We know that the MySQL SELECT command is used to get data from a MySQL table. When you select rows, the MySQL server is free to return them in any order unless you instruct it by stating how to sort the results. However, we can order the result set by adding an ORDER BY clause, which names the column or columns to be sorted.

Syntax

Select column1, column2,…,columN From table_name ORDER BY column1[column2,…];

Example

In the following example, MySQL returns a result set sorted by the "Name" column;

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)

The above is the detailed content of How can we get the sorted MySQL output?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete