PDA

View Full Version : sort one column DESC and second column DESC


jasonc310771
07-23-2008, 09:24 AM
what is the correct method?

this does not work, how can i sort data got from DB by the first column in DESC and then the second column in DESC ?

SELECT * FROM `data` ORDER BY `first` DESC, `second` DESC


thanks

Entanio
07-23-2008, 11:19 AM
Try,

SELECT * FROM `data` ORDER BY `first`, `second` DESC;

:thumbsup:

guelphdad
07-23-2008, 04:22 PM
Entanio, default is ASC so you are going to order that first column ASCENDING order which isn't what is asked.

Jason, what does "does not work" mean exactly? you didn't get an error so did your results come out with the column in the wrong order? are you trying to order a char/varchar type while using numeric values in the column? that happens a lot.

jasonc310771
07-31-2008, 11:44 PM
SELECT * FROM `data` ORDER BY `first` ASC, `second` DESC;

this does not sort the columns correctly

please advise how i should corrctly form this command

thanks in advance for you help

guelphdad
08-01-2008, 08:49 AM
Jason instead of repeating your earlier post, how about qualifying? Can you show us the data in some sample rows and how they appear to be incorrectly ordered?

I'll take one guess, you have numeric data in a char/varchar column and thus it could be ordered this was 1, 10, 100, 2, 3, 30, 3000, 4 for example.