Page 1 of 1

Mysql Problem with id

Posted: Tue Jul 24, 2007 3:58 am
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 ?!

Posted: Tue Jul 24, 2007 10:44 am
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.