If sorting MySQL rows by title doesn’t work..

January 19th, 2010 by Alex Leave a reply »

This took me a while to figure out. I had a very basic table with id, title and couple other fields. But, for some reason, i needed to sort the rows by title, so they will look better in the output. I was trying something very usual like

SELECT * FROM categories ORDER BY title

but that didn’t work somehow… then i added an index on the ‘title’ field, and that didn’t work either.

Now, the problem was that, somehow, the title had some trash at the beginning. So, a basic fix for this was running a simple query to remove that trash:

UPDATE categories SET title = TRIM(title)

Hope that will save some time for people

Comments are closed.