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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.