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
N.M.P.L. Company www.NearMePayday.Loan || 3-month (90 days)
Powered by 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;

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?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2021  www.mysqlfaqs.net
All rights reserved.