# 2.6. ORDER BY

**ORDER BY** sắp xếp kết quả đầu ra của truy vấn. Về mặt logic, nó được áp dụng ở cuối truy vấn. Mệnh đề **ORDER BY** sắp xếp các hàng theo tiêu chí sắp xếp theo thứ tự tăng dần hoặc giảm dần. Mệnh đề **ORDER BY** có thể chứa một hoặc nhiều biểu thức. Mỗi biểu thức có thể tùy ý được theo sau bởi một công cụ sửa đổi thứ tự (ASC hoặc DESC, mặc định là ASC)

**<span style="mso-list: Ignore;">a)<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-r8aowmp6.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-list: Ignore;">b)<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span>Ví dụ:**

Sắp xếp thứ tự các hàng dữ liệu theo cột "**city**":

```mysql
SELECT *
FROM table_name
ORDER BY name;

```

Sắp xếp thứ tự các hàng dữ liệu theo cột "**city**" theo thứ tự giảm giần:

```mysql
SELECT *
FROM table_name
ORDER BY city DESC;

```