Forum Moderators: coopster

Message Too Old, No Replies

MySQL Order By

Change order of VARCHAR

         

yowza

9:27 pm on Sep 15, 2004 (gmt 0)

10+ Year Member



I have a VARCHAR column where most rows start with numbers; however, a few rows start with letters. I have ordered the rows to appear in descending order.

SELECT * FROM db ORDER BY varcharcolumn DESC

With this query the numbers appear in the desired order, but the letters appear before the numbers.

This order makes sense based on my query but I don't want the letters before the numbers.

Is there a way to force the letters to appear after the numbers?

coopster

9:57 pm on Sep 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about sorting them using a string representation of the hexadecimal value?
SELECT * FROM db ORDER BY HEX(varcharcolumn) DESC;

yowza

10:33 pm on Sep 15, 2004 (gmt 0)

10+ Year Member



Wow. Thanks Coopster.

Great solution!

I thought I would have to use subqueries to fix this, but your suggestion made it easy.