MySQL Forums
Forum List  »  Newbie

Re: Order table by record insert order
Posted by: Shlomi Noach
Date: August 30, 2008 11:21AM

Hi,

Generally, you should not rely on the order of rows returned by the DB when you have not specified any order. So if you've ordered by FilmID, you cannot (or rather, should not) expect an insert order in the Name column.

The basic way to solve this is by using an AUTO_INCREMENT column. Usually, this column is the primary key, by which you retireve "natively" ordered results.
But you can use this like this:
Add an "id", auto_increment field,
then add an index (FilmID, id).
When inserting rows, do not specify value for the id column. This way it will increment, and will therefore retain your insert order.
When retrieving, ORDER BY FilmID, id

Shlomi

Options: ReplyQuote


Subject
Written By
Posted
Re: Order table by record insert order
August 30, 2008 11:21AM


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.