Skip navigation links

MySQL Forums :: PHP :: How to select only the first 10 rows on the database?


Advanced Search

Re: How to select only the first 10 rows on the database?
Posted by: Felix Geerinckx ()
Date: September 23, 2005 01:18AM

Kostas Tsirigos wrote:

> SELECT * FROM tbl LIMIT 10 -> to get the first 10 rows

The order in which the above query returns records is unpredictable, and depends on e.g.

- the indexes declared for tbl
- the decisions of the query optimizer
- the storage engine used for tbl
- the records that were deleted
- ...

It might look like the records are returned in insertion order, but that's certainly not always the case.
If you want to have your records returned in a certain order, always include an ORDER BY clause:

SELECT * FROM tbl ORDER BY somecol LIMIT 10;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject Written By Posted
How to select only the first 10 rows on the database? quesxion kexh 09/22/2005 01:41PM
Re: How to select only the first 10 rows on the database? Kostas Tsirigos 09/22/2005 02:57PM
Re: How to select only the first 10 rows on the database? Felix Geerinckx 09/23/2005 01:18AM
Re: How to select only the first 10 rows on the database? quesxion kexh 09/23/2005 02:08AM
Re: How to select only the first 10 rows on the database? Mark Neil Borromeo 09/23/2005 03:52AM
Re: How to select only the first 10 rows on the database? Jay Pipes 09/23/2005 07:45AM
Re: How to select only the first 10 rows on the database? Mark Neil Borromeo 05/08/2006 10:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.