Advertisement: Over 100,000 Jobs Worldwide. Click here to find one for you.

MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
Send This Page to Friend
Enter Friend's Email
Enter Your Email
http://www.kareerlinks.com/jobs/skill/MySQL
 
Home / SQL Statements / Select Statement / Question No: 120

How can I limit the number of rows I want to fetch from my MySQL table?

I want to fetch the desired number of rows from the database. How can I set such limit in MySQL?

Answer No: 120

MySQL provides LIMIT clause to use in the query to fetch desired number of rows from the database. So, you can use LIMIT clause in your query like this:
SELECT buyer_id, buyer_name FROM buyer_table LIMIT 10;
The above query will show first 10 rows from the buyer_table table. However, if you want to fetch last 10 rows of the table, you can also use LIMIT clause for the purpose like below. In the following LIMIT clause example I assume that buyer_id is an auto_increment field:
SELECT buyer_id, buyer_name FROM buyer_table LIMIT 10 ORDER BY buyer_id DESC;

If you want to fetch the rows between 10 and 20 you can again use the LIMIT clause as follow:

SELECT buyer_id, buyer_name FROM buyer_table LIMIT 9, 10;

Comments
Add Comments
Found a bug? Or do you have a better solution for this? Feel free to leave a message:
Leave a comment
Your Name: Your Email Address (optional):
Comment:


Related MySQL FAQs to the Above FAQ

How-to-use-SELECT-statement-to-retrieve-data How to use SELECT statement to retrieve data?

How-does-DISTINCT-work-in-MySQL How does DISTINCT work in MySQL?

How-to-use-ORDER-BY-to-sort-query-results How to use ORDER BY to sort query results?

How-to-use-LIMIT-clause-in-MySQL How to use LIMIT clause in MySQL?

How-to-get-aggregate-results-in-MySQL How to get aggregate results in MySQL?

How-the-select-query-is-executed How the select query is executed?