0

I am wondering if it is possible to query any database entries in order they were inserted without a primary key?

Is there a specification in the SQL which order the entries have on a query like this:

SELECT *
FROM tbl
LIMIT 5
mario.schlipf
  • 1,237
  • 2
  • 13
  • 26

2 Answers2

3

There is not. There is no way to guarantee the row order of the records. You must use ORDER BY.

See MySQL row order for "SELECT * FROM table_name;"

Community
  • 1
  • 1
Kermit
  • 33,206
  • 11
  • 83
  • 119
0

Without specifying ORDER BY, there is no guarantee that your columns will be returned in any particular order -- you should consider it to be random. The order depends on the engine; with MyISAM they will be returned in INSERT order unless there have been updates/deletes. With InnoDB, they will be ordered by the primary key.

If you want your columns to be sorted in a particular order, include an ordinal column / timestamp in the table definition and ORDER BY that.

Explosion Pills
  • 183,406
  • 48
  • 308
  • 385