ใช้ ORDER BY ร่วม LIMIT 10 ไวยากรณ์:
SELECT * FROM yourTableName ORDER BY yourIdColumnName LIMIT 10;
สร้างตาราง:
mysql> create table Clients ( Client_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20) ); Query OK, 0 rows affected (0.51 sec)
แทรกข้อมูล 12 แถว...
แสดงข้อมูล:
mysql> select * from Clients;
ผลลัพธ์ 12 แถว
คำสั่งเลือก 10 แถวแรก:
mysql> select * from Clients ORDER BY Client_Id LIMIT 10;
ผลลัพธ์ 10 แถว (Client_Id 1-10)
วิธีอื่น: LIMIT 0, 10 (offset 0, จำนวน 10)
mysql> select * from Clients limit 0,10;
ผลลัพธ์เหมือนกัน