There is no guarantee that the rows will be returned in any particular order without the ORDER BY in the request.
Consider a simple query that returns all the columns of all rows in a table. For example:
SELECT * FROM mytable ;
For this query, it is likely that MySQL will perform a full table scan from the beginning of the table. Thus, it is likely that the rows will be returned in the order they were in the physical store.
This may roughly correspond to the order in which the rows were inserted if there were no deletions, no updates, no reorganization, where the space for the inserted row was subsequently freed and reused to store the newly inserted row.
But this behavior is not guaranteed.
To return rows in the order in which they were inserted, the query must specify the sequence in which the rows should be returned, including the ORDER BY .
For rows that should be returned in the "insertion order", this means that the request should be able to have this information available or be able to receive it. For a simple query on a single table, this means that the information should be stored in a row.
spencer7593
source share