Re: Intersect and order by - Mailing list pgsql-general

From Michael Fork
Subject Re: Intersect and order by
Date
Msg-id Pine.BSI.4.21.0102281349080.9658-100000@glass.toledolink.com
Whole thread Raw
In response to Intersect and order by  (Michaël Fiey <m.fiey@futuresoundtech.com>)
List pgsql-general
Either of these should fix your problem:

SELECT col1 as my_col
FROM table
WHERE <conditions 1>
INTERSECT
SELECT col1 as my_col
FROM table
WHERE <conditions 2>
ORDER BY my_col

- OR -

SELECT col1
FROM table
WHERE <conditions 1>
INTERSECT
SELECT col1
FROM table
WHERE <conditions 2>
ORDER BY 1
        ^^^
        Ordinal value of field to order by

To use UNION/INTERSECT/EXCEPT with ORDER BY, you must order by the ordinal
value of the field or by the aliased field name.

Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio

On Wed, 28 Feb 2001, [iso-8859-1] Micha�l Fiey wrote:

> Hi,
>
> I don't understand what's happening with my command
> I read postgresql docs, it should work...What's the problem ?
> The command is :
>
> select col1
> from table
> where <conditions 1>
> intersect
> select col1
> from table
> where <conditions 2>
> order by col1
>
> It does not work and return "get_sortgroupclause_expr: ORDER/GROUP BY
> expression not found in targetlist"
>
> I use pgsql 7.03 ont redhat 7.0.
>
> Any help would be appreciated
>
> michael
>
>
>


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Slowdown problem when writing 1.7million records
Next
From: Tom Lane
Date:
Subject: Re: Intersect and order by