Re: ORDER BY in UNION query

From: Richard Huxton <dev(at)archonet(dot)com>
To: Antony Paul <antonypaul24(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY in UNION query
Date: 2005-01-10 12:58:26
Message-ID: 41E27BF2.8080701@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Antony Paul wrote:
> Hi,
> I need to use ORDER BY clause in a UNION query and the Order BY
> columns are not included in the SELECT statement. I tried like this
>
> (select .... from a) UNION (select ..... from b) order by a.ename;
>
> It says that
> ERROR: Attribute "ename" not found
>
> How to do this.

The "order by" is applying to the results of the union, not one of the
sub-selects. If you want to sort by a value, you'll need to include it
in the results list.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Sidney-Woollett 2005-01-10 13:10:42 Re: ORDER BY in UNION query
Previous Message Mark Rae 2005-01-10 12:26:49 Re: PostgreSQL 8.0.0 Release Candidate 4