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

How can we get the sorted MySQL output?

WBOY
Release: 2023-08-31 16:13:07
forward
614 people have browsed it

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,…];
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template