Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select first 10 elements from database using SQL?

Tags:

sql

mysql

There is a query like SELECT * FROM clients ORDER BY id. I want to select only first 10 elements. How can I do this?

P.S. I'm using MySQL.

like image 705
Sergey Avatar asked Nov 07 '09 17:11

Sergey


2 Answers

SELECT * FROM clients ORDER BY id LIMIT 10;
like image 142
Luke Bayes Avatar answered Oct 12 '22 22:10

Luke Bayes


Note that OFFSET is very helpful to paginate:

LIMIT 10 OFFSET 11

for the second page of 10.

like image 24
David W Avatar answered Oct 12 '22 23:10

David W