Search⌘ K
AI Features

Sort Results

Explore how to sort database query results using the ORDER BY clause in MySQL. Understand how to order data by different columns in ascending or descending order for better data analysis and presentation.

We'll cover the following...

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
...