On the web I see a lot of questions of developers who are wanting to know how they can retrieve only the first N records in their queries.
The answer is simple, LIMIT
For example, if you only want to select the top 5 names from a names tables, use the following query:
SELECT `firstname`,`lastname` FROM `names` ORDER BY `firstname` LIMIT 0,5
This query will return only the first 5 names from the names table.
If you want to select the first 10, use the following query:
SELECT `firstname`,`lastname` FROM `names` ORDER BY `firstname` LIMIT 0,10
Related posts:
- 11 MySQL resources you must read! Conditional joins in MySQL One way to do a “Conditional...
- The 20 best practices when using MySQL Just came across this great article with 20 best practices...
- Scaling up your MySQL server We use MySQL on most of our projects. One of...
- 15 essential PHP and MySQL tutorials! Showing Google Maps with many markers in PHP Sometimes you...
Related posts brought to you by Yet Another Related Posts Plugin.