Sort Results
Learn to sort the results in ascending and descending order.
Use of order by
There are many times that we want the results to be returned in a specific order. For example, let’s suppose that we want to get the list of products in ascending order of name
. This is how we do that:
MySQL
select * from products order by name;
We get the following output from the above code:
1 mysql> select * from products order by name;
2 +----+----------------------------+-------+
3 | id | name |price |
4 +----+-----------------------------+-------+
5 | 3 | A
...