Re: Need to overcome UNION / ORDER BY restriction

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Timo <siroco(at)suomi24(dot)fi>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need to overcome UNION / ORDER BY restriction
Date: 2003-09-29 17:15:03
Message-ID: 20030929171503.GA10856@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Sep 29, 2003 at 17:27:47 +0300,
Timo <siroco(at)suomi24(dot)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 | 271
935 | 1 | 276
924 | 1 | 581
902 | 2 | 271
902 | 3 | 271
972 | 2 | 275
935 | 2 | 276
924 | 2 | 581
924 | 3 | 581
(9 rows)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-09-29 17:40:55 Re: [SQL] Conditional row grained + FK dependency oriented lazy replication
Previous Message GRIMOIS Eric 2003-09-29 17:12:08 Re: SRF Functions don't want to return empty tuple