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
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
There is not. There is no way to guarantee the row order of the records. You must use ORDER BY
.
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.