dbTalk Databases Forums  

Union Clause

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Union Clause in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: Union Clause - 05-06-2008 , 01:04 AM






Mtek wrote:
Quote:
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

--
Peter


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.