Re: ORDER BY in UNION query

From: John Sidney-Woollett <johnsw(at)wardbrook(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 13:10:42
Message-ID: 41E27ED2.1080203@wardbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try

select a.col1 as ename from a
union
select b.othercolumn as ename from b
order by ename

Give the columns you want to order on the same name using the "as XXX"
syntax, and remove the "a." prefix from the order statement.

John Sidney-Woollett

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.
>
> rgds
> Antony Paul
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-01-10 13:30:26 Re: Transaction size
Previous Message Richard Huxton 2005-01-10 12:58:26 Re: ORDER BY in UNION query