# 2.7. LIMIT

**LIMIT** là một mệnh đề dùng để giới hạn số lượng hàng dữ liệu được trả về trong một truy vấn . Về mặt logic, nó được áp dụng ở cuối truy vấn. Mệnh đề **LIMIT** hạn chế số lượng hàng được truy vấn.

**<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:**

**<span style="mso-no-proof: yes;"> </span>**

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

**<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ụ:**

Lấy 5 hàng dữ liệu trong truy vấn.

```mysql
SELECT *
FROM table
LIMIT 5;

```

Lấy 5 giá trị lớn nhất trong cột “**name**”.

```mysql
SELECT city, count(*) AS population
FROM table
GROUP BY name
ORDER BY value DESC
LIMIT 5;

```

<div class="eJOY__extension_root_class" id="bkmrk--2" style="all: unset;"></div>