MySQL Forums
Forum List  »  PHP

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;

Please use BBCode to format your messages in this forum.

Options: ReplyQuote

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.