help with query: advanced ORDER BY... - Mailing list pgsql-novice

From
Subject help with query: advanced ORDER BY...
Date
Msg-id 00ac01c6192a$3c487460$6402a8c0@iwing
Whole thread Raw
Responses Re: help with query: advanced ORDER BY...  (Michael Fuhr <mike@fuhr.org>)
List pgsql-novice
hi list

here's what i would like to do:

table1:
field0: id
field1: boolean
field2: numeric
field3: varchar

when selecting records from this table, i would like to have different sort
orders depending if field1 is true or false: all records with field1 = true
should be sorted with field2 first then field3, all records having field2 =
false sorted by field3 first then field2.

example:

field0  |  field1 |  field 2 |  field3
-------------------------------------------
1            t           2           b
2            f           1           z
3            t           1           a
4            f            4           a


desired output after sorting
4            f            4           a
2            f           1           z
3            t           1           a
1            t           2           b

is this possible in a single query?

(i hope my explanations make sense ;-))

- thomas



pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: How to set a Default Value
Next
From: Michael Fuhr
Date:
Subject: Re: help with query: advanced ORDER BY...