Re: Unions and Grouping

From: Ragnar <gnari(at)hive(dot)is>
To: Aaron Bono <postgresql(at)aranya(dot)com>
Cc: Postgres SQL language list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unions and Grouping
Date: 2006-12-15 22:30:09
Message-ID: 1166221809.6369.202.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On fös, 2006-12-15 at 16:17 -0600, Aaron Bono wrote:
> On 12/15/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Aaron Bono" <postgresql(at)aranya(dot)com> writes:
> > My question, what do the SQL Specifications say should
> happen on a Union?
> > Is it supposed to eliminate duplicates even WITHIN the
> individual queries
> > that are being unioned?
>
> Yes. SQL92 7.10 saith:
> [snip SQL92 standardese]

>
> So if I don't want the duplicated WITHIN the two queries to be
> eliminated, I use UNION ALL?

with UNION ALL, no duplicates will be discarded, either
"within" or "between" the queries.

if I understand you, you are looking for having only queries
that are both in Q1 and Q2 removed, but not for example,
any duplicates in Q1 that are not in Q2.

if this is what you want, then I think you may not have
thought it through. what about a row that is twice in
Q1 and three times in Q2? how many copies of this row
should be in the result?

gnari

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-12-15 22:41:52 Re: Unions and Grouping
Previous Message Aaron Bono 2006-12-15 22:17:20 Re: Unions and Grouping