[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] Intersect and order by
From:       Michael Fork <mfork () toledolink ! com>
Date:       2001-02-28 18:55:47
[Download RAW message or body]

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
> 
> 
> 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic