Mysql Sort order very Weird
-
23-08-2019 - |
Question
SELECT events.title
FROM events
ORDER BY events.title DESC
I'm getting the proper ordering for all but a couple events at the end of my table.
The encoding on the title table is utf8_general_ci
. I've tried retyping the the title, hoping it was using some weird russian characters I couldn't see, but it still appears in the wrong order.
Solution
Just a wild guess, but maybe some of your titles have some spaces at the beginning.
If that is your problem, you can use
Order By TRIM(events.title) DESC
But that will slow down your query because MySQL won't be able to use the index on title if you have one.
OTHER TIPS
Could you please run
SELECT HEX(CAST(title AS BINARY))
FROM events
WHERE id = @weird_record
and post the output here?
Update:
It seems that the record is plain ASCII
, no leading spaces of weird characters, and says Walters Brothers Rebellion
Could you please do the same for a recors which is out of order?
Please pick some record that should come before the Walter Brothers
but comes after, of vice versa, and post the results of the same query.