Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread Chris
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, ordere

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread David Mitchell
How about a union? SELECT * FROM productgroup WHERE groupid = $productid AND label = 'Cats' ORDER BY title UNION SELECT * FROM productgroup WHERE groupid = $productid AND label != 'Cats' ORDER BY label,title Also, for long-term maintenance, it would probably be better to list the columns rather

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread tg-php
Yeah, that's a bit of an important piece of information. Some tricks do work across versions of SQL, but not always. Something else you can try is creating an artificial column to sort by. Excuse the code, it's been ages since I've worked with MS SQL so syntax is probably off, but just to dem

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread Bryan
I think there's one small piece of data I left out. I'm working with php/mssql, not mysql. I'll move to mysql when I get everything else built. Mssql 2000 doesn't seem to like the = sign in the order by clause. It looks like both of you so far have come up with the same syntax though so it must

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread Bryan
I think there's one small piece of data I left out. I'm working with php/mssql, no mysql. I'll move to mysql when I get everything else built. Mssql 2000 doesn't seem to like the = sign in the order by clause. It looks like both of you so far have come up with the same syntax though so it must

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread tg-php
Try this: SELECT * FROM productgroup WHERE groupid = $productid ORDER BY label = 'Cats' DESC, title The test SQL I did to make sure I understood it was this (against our Users table): select * from users order by first = 'Bob' DESC, first, last It put all the "Bob"s first, sorting them by firs

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread Stut
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, ordere

[PHP-DB] sql statement - complex order by

2007-07-02 Thread Bryan
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