Re: UNION?

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: Forest Felling <res08i7v(at)verizon(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: UNION?
Date: 2003-01-20 15:34:22
Message-ID: i95o2v8qnm8iagfihnm5st6fdhtft1fnf8@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, 20 Jan 2003 08:52:09 -0500, Forest Felling
<res08i7v(at)verizon(dot)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

In response to

  • UNION? at 2003-01-20 13:52:09 from Forest Felling

Browse pgsql-novice by date

  From Date Subject
Next Message Manfred Koizar 2003-01-20 15:47:35 Re: OID
Previous Message Tom Lane 2003-01-20 15:33:30 Re: Database Performance problem