Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Bỏ qua 10 kết quả đầu trong MySQL

Dùng LIMIT offset để bỏ qua bản ghi đầu.

Cú pháp:

select *from yourTableName limit 10 offset lastValue;

Tạo bảng 15 bản ghi:

mysql> create table SkipFirstTenRecords
-> (
-> StudentId int,
-> StudentName varchar(200)
-> );
Query OK, 0 rows affected (0.53 sec)

Chèn 15 sinh viên (ID 100-114).

Hiển thị tất cả:

mysql> select *from SkipFirstTenRecords;

Kết quả 15 hàng.

Bỏ 10 đầu, lấy 5 cuối:

mysql> select *from SkipFirstTenRecords limit 10 offset 10;

Kết quả:

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 110       | Aaron       |
| 111       | Peter       |
| 112       | Travis      |
| 113       | Alex        |
| 114       | Pat         |
+-----------+-------------+
5 rows in set (0.00 sec)