Re: sql statement - complex order by
| From: | Chris | Date: | Tue, 03 Jul 2007 02:15:38 +0000 |
| Subject: | Re: sql statement - complex order by | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43738@lists.php.net to get a copy of this message | ||
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?select *, case when label='cats' then 1 else 2 end as order_by where groupid=$productid order by order_by, title; See http://www.databasejournal.com/features/mssql/article.php/3288921 for a better example. -- Postgresql & php tutorials http://www.designmagick.com/