Re: sql statement - complex order by

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bryan wrote:
SELECT * FROM productgroup WHERE groupid = $productid
AND label =  'Cats' ORDER BY title

SELECT * FROM productgroup WHERE groupid = $productid
AND label != 'Cats' ORDER BY label,title

I'd like to find a way to combine these 2 statements. I want to list out all the products, ordered by title but listing out all the Cats products first. Any way to do that without having separate statements?

Thanks...

select * from productgroup where groupid = $productid order by (label = 'Cats') desc, title

And I do hope you're properly validating and escaping $productid.

-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux