Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group