Order By using characters.. [Solved]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Order By using characters.. [Solved]

Post by waskelton4 »

Hello,

I have a query that is returning rows that need to be ordered by an ID that holds one or two characters.

the IDs are A, B, C, D,.... X, Y, Z, AA, BB, CC ...

Is there a way i can order this in the order shown above without creating another table and using numerical keys to associate those values. Currently the order is A, AA, B, BB, C, CC.....

Thanks for any help!
Will
Last edited by waskelton4 on Thu May 05, 2005 1:51 pm, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If you are using MySQL, you could try something like:

Code: Select all

SELECT CHAR_LENGTH(name) AS length, *
FROM table
ORDER BY length ASC, name DESC
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Order By using characters. [solved]

Post by waskelton4 »

Perfect..

Thanks!!
Post Reply