On 1 Apr 2015, at 9:29am, Bart Smissaert <bart.smissaert at gmail.com> wrote:

> This needs to be sorted on column A asc
> Then when the value in A is 1 the second sort needs to be asc on column B,
> but when the value in A is 2 then the second sort  needs to be asc on
> column C.

You just put it all in your ORDER BY clause.

SELECT * FROM myTable ORDER BY a, (CASE a WHEN 1 THEN b WHEN 2 THEN c END) ASC

What you can't do is create an index which perfects suit this clause.  You'll 
get the right results but not as quickly as a clause with an ideal index.  I 
can think of a few indexes which the planner might take advantage of, but not 
any which are ideal.

Simon.

Reply via email to