Re: UNION? - Mailing list pgsql-novice

From Manfred Koizar
Subject Re: UNION?
Date
Msg-id i95o2v8qnm8iagfihnm5st6fdhtft1fnf8@4ax.com
Whole thread Raw
In response to UNION?  (Forest Felling <res08i7v@verizon.net>)
List pgsql-novice
On Mon, 20 Jan 2003 08:52:09 -0500, Forest Felling
<res08i7v@verizon.net> wrote:
>mydb=# select count(city) as qty, code as code
>    from test_year
>    where length(code) = 1
>    group by code
>    order by code
>    union all
>    select count(city) as qty, 'All' as code
>    from test_year
>    where length(code) = 1
>ERROR:  parser: parse error at or near "all"
>Drop ALL, and get
>ERROR:  parser: parse error at or near "select"

Try
    SELECT * FROM (
        SELECT ...
          FROM test_year ...
         GROUP BY ...
         ORDER BY ... ) AS t1
    UNION ALL
    SELECT count(...), 'All' ...

or
    SELECT 1, count(city) as qty, code as code
      FROM ...
     GROUP BY
    UNION ALL
    SELECT 2, count(city) as qty, 'All' as code
      FROM ...
     ORDER BY 1, 3;

Servus
 Manfred

pgsql-novice by date:

Previous
From: Conxita Marín
Date:
Subject: Re: quoted_literal with numeric variable
Next
From: Tom Lane
Date:
Subject: Re: Database Performance problem