help with query: advanced ORDER BY...

From: <me(at)alternize(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: help with query: advanced ORDER BY...
Date: 2006-01-14 16:47:41
Message-ID: 00ac01c6192a$3c487460$6402a8c0@iwing
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2006-01-14 17:18:29 Re: help with query: advanced ORDER BY...
Previous Message Michael Fuhr 2006-01-13 18:29:54 Re: How to set a Default Value