[sqlite] Two different Order By in one statement

2015-04-01 Thread R.Smith
On 2015-04-01 10:29 AM, Bart Smissaert wrote: > OK, let me give the simplest example possible. > > Table with 3 integer fields, A, B and C > > AB C > > 1 1 2 > 2 1 2 > 1 2 1 > 2 2 1 > > This needs to be sorted on column A asc >

[sqlite] Two different Order By in one statement

2015-04-01 Thread Bart Smissaert
Also, performance is very good with a compound index on emis_number, status, entry_date, significance. RBS On Wed, Apr 1, 2015 at 11:06 AM, Bart Smissaert wrote: > Thanks, that does work indeed. My actual real order is now this: > > ORDER BY emis_number asc, status desc, > (case status when 2 t

[sqlite] Two different Order By in one statement

2015-04-01 Thread Bart Smissaert
Thanks, that does work indeed. My actual real order is now this: ORDER BY emis_number asc, status desc, (case status when 2 then entry_date when 1 then significance end) desc, entry_date desc All working perfect. Never realised you could do this. RBS On Wed, Apr 1, 2015 at 10:03 AM, Simon Slav

[sqlite] Two different Order By in one statement

2015-04-01 Thread Simon Slavin
On 1 Apr 2015, at 9:29am, Bart Smissaert 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.

[sqlite] Two different Order By in one statement

2015-04-01 Thread Bart Smissaert
OK, let me give the simplest example possible. Table with 3 integer fields, A, B and C AB C 1 1 2 2 1 2 1 2 1 2 2 1 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

[sqlite] Two different Order By in one statement

2015-04-01 Thread R.Smith
On 2015-04-01 01:50 AM, Bart Smissaert wrote: > Say I have a table with 3 fields. Depending on a value in field 1 (this > value will be either 1 or 2) > I want to do a different sort order sorting on fields 2 and 3. > This will be either order by field2 desc, field3 desc or field3 desc, > field2

[sqlite] Two different Order By in one statement

2015-04-01 Thread Bart Smissaert
Say I have a table with 3 fields. Depending on a value in field 1 (this value will be either 1 or 2) I want to do a different sort order sorting on fields 2 and 3. This will be either order by field2 desc, field3 desc or field3 desc, field2 desc. I thought of a union, but doesn't allow this. Any su

[sqlite] Two different Order By in one statement

2015-03-31 Thread Igor Tandetnik
On 3/31/2015 7:50 PM, Bart Smissaert wrote: > Say I have a table with 3 fields. Depending on a value in field 1 (this > value will be either 1 or 2) > I want to do a different sort order sorting on fields 2 and 3. > This will be either order by field2 desc, field3 desc or field3 desc, > field2 desc

[sqlite] Two different Order By in one statement

2015-03-31 Thread Darren Duncan
I don't know what you mean by "technically impossible". What Bart asked for is entirely possible, and commonly done. You very well can put an arbitrary expression in an ORDER BY clause, including a CASE statement, so that it does what is requested. Failing that, you can use an inner query in