Re: Small SQL Puzzle
Posted in 1998
>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?
I didn't see the original posting, just someone's reply, and the above may not quote the
entire message. Given that, I notice that there is no "group by" clause in the final
select statement. What do you get with:
select col1, count(*)
from temp
group by 1
having count(*) = 1;
Mark Collins
mcollins@us.dhl.com
The problem lies in how easily and dangerously we forget that
manipulating things is not the same as understanding them.