K
K
Katerina Paskova2020-01-08 13:30:12
MySQL
Katerina Paskova, 2020-01-08 13:30:12

Why doesn't MySQL sort by date correctly?

There is a table with orders.
5e15ae4acc98b453706995.png
And I need to get all orders from it by date in reverse order. I wrote this query:

SELECT id, DATE_FORMAT(date, "%d.%m.%Y") as date, status
FROM orders
ORDER BY date DESC

But for some reason it displays orders in discord, without any sorting.
5e15af002d314607188432.png
Why doesn't sorting work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-01-08
@KatyaPaskova

Because after DATE_FORMAT you are not sorting dates, just strings.
Try like this:ORDER BY orders.date DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question