Re: ORDER BY

From: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
To: "Alexander Staubo" <alex(at)purefiction(dot)net>, "MicroUser" <a(dot)shafar(at)gmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: ORDER BY
Date: 2006-11-15 22:59:04
Message-ID: 8C5B026B51B6854CBE88121DBF097A865D43BB@ehost010-33.exch010.intermedia.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> For larger tables, you may have to resort to a
> union:
>
> select * from foo where name != 'Other' order by name
> union
> select * from foo where name = 'Other'

Alas, this suggestion is wrong on two counts: (a) UNION expects a single
ORDER BY that applies to the whole recordset and which has to come at
the end; (b) UNION re-sorts anyway (it needs to eliminate the dupes) --
maybe you are thinking UNION ALL? So, to follow your advice he may want
a query like this, although it seems quite silly and there still isn't
an ironclad guarantee re. the final result sorting:

select * from
(select * from foo where name != 'Other' order by name) x
union all
select * from foo where name = 'Other'

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Morris Goldstein 2006-11-15 23:18:11 Transaction id wraparound problem
Previous Message whytwelve13@yahoo.com 2006-11-15 22:37:12 Re: PgSQL not recognized