Re: Small SQL Puzzle
Posted in 1998
Karl & Betty Schendel — — source: Informix-list mailing list archive (1991-1998)
On Thu, 26 Feb 1998 11:32:24 +0000, Paul Watson <watson@mcmail.com> wrote:
>Consider the following
>
>select col1, count(*)
> from tab1
> group by 1
> having count(*) = 1
>union
>select col1, count(*)
> from tab2
> group by 1
> having count(*) = 1>
>Gives x rows
>
>Next
>
>select col1
> from tab1
>union
> select col1
> from tab2
>into temp table;>
>select col1, count(*)
>from temp
>having count(*) =1>
>gives y rows
>
>The obvious question is why doesn't x=y?
Because the second union eliminates duplicates from BOTH tab1 and tab2 together, rather
than just dups from tab1 then dups from tab2. I would expect that x >= y, right?
Karl