tags:

views:

163

answers:

2

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.

Suggestions?

Thanks

+2  A: 

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

[Edit]

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.

Eric Hogue
Good suggestion! It may be helpful to run a query such as SELECT CONCAT('[', events.title, ']') FROM events to see if there are leading or trailing spaces.
Bill Karwin
Ran `UPDATE events SET title = TRIM(title)` Worked like a charm thanks!
Allain Lalonde
Good, I didn't propose the update because I didn't know if changing the data was an option.
Eric Hogue
A: 

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.

Quassnoi
57616C746572732042726F746865727320526562656C6C696F...
Allain Lalonde