Mysql Sort order is very strange

SELECT events.title 
FROM events 
ORDER BY events.title DESC

      

I am getting the correct order for all but a couple of events at the end of my table.

The encoding in the header table is utf8_general_ci

. I tried to retype the title, hoping it uses strange Russian characters that I couldn't see, but still appears in the wrong order.

0


a source to share


2 answers


Just a wild guess, but maybe some of your titles have spaces at the beginning.

If this is your problem, you can use



Order By TRIM(events.title) DESC 

      

But this will slow down your query, because MySQL will not be able to use the header index if you have one.

+2


a source


Could you run

SELECT HEX(CAST(title AS BINARY))
FROM   events
WHERE  id = @weird_record

      

and post the output here?

Update:



The entry seems to be simple ASCII

, contains no strange characters leading spaces, and saysWalters Brothers Rebellion

Could you do the same for the intruders who are out of order?

Select some record that should appear before Walter Brothers

, but will appear after, on the contrary, and publish the results of the same query.

0


a source







All Articles