Re: Unions and Grouping

From: "Aaron Bono" <postgresql(at)aranya(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Postgres SQL language list" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unions and Grouping
Date: 2006-12-15 22:17:20
Message-ID: bf05e51c0612151417o1bdfa65bh5e869185469f46e1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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:
>
> b) If a set operator is specified, then the result of applying
> the set operator is a table containing the following rows:
>
> i) Let R be a row that is a duplicate of some row in T1 or
> of
> some row in T2 or both. Let m be the number of duplicates
> of R in T1 and let n be the number of duplicates of R in
> T2, where m >= 0 and n >= 0.
>
> ii) If ALL is not specified, then
>
> Case:
>
> 1) If UNION is specified, then
>
> Case:
>
> A) If m > 0 or n > 0, then T contains exactly one
> dupli-
> cate of R.
>
> B) Otherwise, T contains no duplicate of R.
>
>
> regards, tom lane
>

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

Thanks!

--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ragnar 2006-12-15 22:30:09 Re: Unions and Grouping
Previous Message Tom Lane 2006-12-15 21:42:04 Re: Unions and Grouping