Mysql Problem with id

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hesham2012
Forum Newbie
Posts: 8
Joined: Fri Mar 09, 2007 11:34 pm

Mysql Problem with id

Post by hesham2012 »

a strange problem faced me with my database

when i insert a data into a table suppose a, b, c, d

i expect that they are inserted in rows like this

id value
1 a
2 b
3 c
4 d

but what happens something else like this


id value
4 d
3 c
2 b
1 a


and sometimes like this

id value
1 a
3 c
2 b
4 d


but when i converted the table from MyIsam to InnoDB i think this problem has finished . What happens ?!
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Never be dependent on the physical order of rows in a database. If you do an insert, then a select, there is no guarantee that the last row you inserted will be the last row returned by the select.

Make sure you use ORDER BY when retrieving records, or add in your own order field or inserted datetime field. Even if the problem seems to have gone away, don't depend on those records being ordered by when they were inserted.
Post Reply