Limiting Your Results

Limiting Your Results

For limiting the result from select query you can use use the LIMIT clause. Which will return only a certain number of records in your SELECT query result. There are two requirements when using the LIMIT clause: offset and number of rows. The offset is the starting position, and the number of records you want from the start offset position.

In general the offset starts from 0.

Few examples to demonstrate the LIMIT

1. SELECT * FROM users LIMIT 0, 10;
2. SELECT * FROM users LIMIT 10, 10;
3. SELECT * FROM users ORDER BY name LIMIT 20, 10;

The sql will not fire any error if your limit is beyond the number of query exist
for example if the users table contain 20 records

then ” SELECT * FROM users LIMIT 40, 10;”

will not give you error message .It will return empty set .

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.