Re: Union Clause
Date: Mon, 5 May 2008 23:04:12 -0700 (PDT)
Message-ID: <519c9a6e-c0d2-4034-bc60-b24cda2cf2ce@w8g2000prd.googlegroups.com>
Mtek wrote:
> Hi,
>
> This is my query:
>
> SELECT SUM(zcom) + SUM(ze) + SUM(zp)
> FROM
> (SELECT count(DISTINCT(email)) FROM customers_lookup) zcom
> UNION
> (SELECT count(DISTINCT(email)) FROM customers_lookup) ze
> UNION
> (SELECT count(DISTINCT(email)) zp FROM customers_lookup) zp);
>
> Basically I want to get a count from the three tables where the email
> address appears in ALL THREE tables. If an email does not exist in
> all three tables, then I do not want it counted.......
Use INTERSECT, not UNION.
Or use a normal inner join...
select count(distinct a.email)
from
customers_lookup a
inner join customers_lookup_ze b on b.email = a.email
inner join customers_lookup_prim c on c.email = b.email
-- PeterReceived on Tue May 06 2008 - 01:04:12 CDT