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
4

2 回答 2

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;"

于 2013-03-30T16:50:00.470 回答
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.

于 2013-03-30T16:51:42.703 回答