RE: Result ordering

2008-11-30 Thread Martin Gainty
instead of > SELECT name, (CASE WHEN bar = 34 THEN 0 ELSE 1 END) AS rank> FROM foo> WHERE > bar = 34> OR baz > 100> ORDER BY rank ASC, baz DESC> LIMIT 5; you can use order the query evaluation to perform inner subquery first select distinct foo.name,foo.bar,baz.bar from foo where exists (selec

Re: Result ordering

2008-11-30 Thread Morten
On Nov 30, 2008, at 11:42 PM, Andy Shellam wrote: Hi Morten, I think this is valid in MySQL (it certainly is for SQL Server) but you can use a CASE statement directly in the ORDER BY clause. Try something like this: SELECT name FROM foo WHERE bar = 34 OR baz > 100 ORDER BY CASE ba

Re: Result ordering

2008-11-30 Thread Andy Shellam
Hi Morten, I think this is valid in MySQL (it certainly is for SQL Server) but you can use a CASE statement directly in the ORDER BY clause. Try something like this: SELECT name FROM foo WHERE bar = 34 OR baz > 100 ORDER BY CASE bar WHEN 34 THEN 0 ELSE 1 END ASC, baz DESC LIMIT 5; Re