Re: Need to overcome UNION / ORDER BY restriction - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: Need to overcome UNION / ORDER BY restriction
Date
Msg-id 20030929171503.GA10856@wolff.to
Whole thread Raw
In response to Need to overcome UNION / ORDER BY restriction  ("Timo" <siroco@suomi24.fi>)
List pgsql-sql
On Mon, Sep 29, 2003 at 17:27:47 +0300, Timo <siroco@suomi24.fi> wrote:
> 
> I'd need to get a result set where rows are sorted according to these rules:
> 
> 1. first all rows with priority = 1 sorted according to seniority
> 2. then the rest of the rows sorted by seniority, priority

You can do something like:
bruno=> select * from foo order by priority <> 1, seniority, priority;id  | priority | seniority
-----+----------+-----------902 |        1 |       271935 |        1 |       276924 |        1 |       581902 |
2|       271902 |        3 |       271972 |        2 |       275935 |        2 |       276924 |        2 |       581924
|       3 |       581
 
(9 rows)


pgsql-sql by date:

Previous
From: Doris Bernloehr
Date:
Subject: SQL Syntax problem
Next
From: Josh Berkus
Date:
Subject: Re: postgres index on ILIKE