How can we sort MySQL output in ascending order?

MySQLMySQLi Database

We need to specify ASC (short form for ASCENDING) keyword in ORDER BY clause if we want to sort out the result set in ascending order.

Syntax

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

Example

In the following example, we have sorted the result set by column ‘Name’ in the ascending order.

mysql> Select * from Student ORDER BY Name ASC;
+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 2    | Aarav   | Mumbai  | History   |
| 1    | Gaurav  | Delhi   | Computers |
| 15   | Harshit | Delhi   | Commerce  |
| 17   | Raman   | Shimla  | Computers |
+------+---------+---------+-----------+
4 rows in set (0.00 sec)
raja
Published on 19-Feb-2018 15:33:41
Advertisements