• Teach Your Self With
             w3htmlschool.com

MySQL ORDER BY clause

The MySQL ORDER BY clause will return output rows in a specific order.
Ascending order is default
Specify order with ASC and DESC

Syntax


SELECT
columns
FROM
table_name
WHERE
where_conditions
ORDER BY columns
Table
+-------------+----------+
| Field | Type |
+-------------+----------+
| ID | int(11) |
| Name | char(35) |
| CountryCode | char(3) |
| District | char(20) |
| Population | int(11) |
+-------------+----------+
Example
select name from city order by name limit 10;
Output

+-------------------+
| name |
+-------------------+
| Alger |
| Alkmaar |
| Almere |
| Amersfoort |
| Amsterdam |
| Annaba |
| Apeldoorn |
| Arnhem |
| ´s-Hertogenbosch |
| Batna |
+-------------------+
10 rows in set (0.00 sec)