• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

MySQL ORDER BY

themoose

Sup, Recoil here.
NLC
Does anybody know if it's possible to ORDER BY something conditionally

Basically, I want to order by `ranking` ASC where `ranking` isn't '0' , and then display the '0' ones afterwards.

I know it's easily done with more than one query but I'm interested to know if it's possible with just one query.

Currently it's:

0
0
0
0
1
5
38
192

And I want:

1
5
38
192
0
0
0
0
 
sorry i didn't gave you a good answer, also my question is written badly. I can make it display this:
1
5
28
192
Without 0, it will be like this
Code:
SELECT * FROM `table` WHERE rank > 0 ORDER BY rank ASC
 
I want the 0, but I want them to be ordered after the other numbers.

It's probably not possible with 1 query (I know definitely it is with 2) - but that's what I'm after.
 
use COUNT(*) to get the total number of rows, then use numrows to get rows that are NOT 0, then subtract numrows from COUNT(*) and you have the number of entries that are 0.
 
Back
Top