Search code examples
mysqldockerpercona

MySQL incorrect ordering


I have a table for example: id | name | date_add

With content:

1| Mark | 2018-02-01 10:00:00

2| Andrew | 2018-02-01 10:00:00

When I try to do this request: select * from table order by date_add

I get rows in the next order: 2, 1

It occurs in Percona MySQL docker

With the same Percona on my host machine I got in 1, 2 order

How to enable logic in Docker as at my host machine?


Solution

  • Unless specified in and ORDER BY clause, row ordering is indeterminate. There is no default ordering (or sub-ordering) that you should expect to obtain.

    In this case, you should specify an ordering clause:

    ORDER BY date_add, id
    

    This behavior may be influenced by Percona or Docker, but again, you should not expect any apparent "default" ordering to appear, even between queries made minutes apart. See also What is the default Order By of queries?