views:

86

answers:

2

I have a page that show "special offers", and i need to order the results by discount value. Besides i want that products with quantity=0 are shown at the end of the list (regardless of the discount value).

So, there is any way to do that using only SQL? I mean... if i set "ORDER BY discount, quantity DESC" the list show products ordered by discount, and each groups of discout is ordered by the quantity value... this isn't what i want.

Thanks in advance...

+6  A: 

ORDER BY CASE Quantity WHEN 0 THEN 99999999 ELSE Discount END, Quantity DESC

Michael Pakhantsov
@Michael: thanx man, i will try this...
Luciano
A: 
SELECT * FROM `products` ORDER BY discount WHERE quantity > 0
UNION SELECT * FROM `products` WHERE quantity <= 0;

Like this?

aularon
@aularon: using this syntax i'm excluding quantity<0, or am i wrong?
Luciano
sorry, fixed now.
aularon