Jump to content

sort by column 1 then by column 2


jasonc

Recommended Posts

sorting results got from mysql.

 

i wish to sort results by the columns ID then by NUMBER,

both with the highest numbers first.

 

i have this mysql code so far but it firstly sorts the ID column but has 99 above 990 !

 

can i sort so it is strict number order?

 

select * from `list` ORDER BY `number` DESC LIMIT 600

Link to comment
https://forums.phpfreaks.com/topic/108960-sort-by-column-1-then-by-column-2/
Share on other sites

It would be very strange if it sorted the id columns, given you wrote "ORDER BY number".

Your clause should be ORDER BY id desc, `number` desc, but if columns are not numeric, of course you'll get 99 before 990. In that case you should do this

 

SELECT *, cast(id as integer) as numid, cast(`number` as integer) as numnumber ORDER BY numid desc, numnumber desc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.