Re: Left Join 3 tables

From: David W Noon <dwnoon(at)spamtrap(dot)ntlworld(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Left Join 3 tables
Date: 2003-05-15 11:39:38
Message-ID: rsacp-4oi.ln1@my-pc.ntlworld.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wednesday 14 May 2003 18:35 in
<27ad91d2(dot)0305140935(dot)4fdec226(at)posting(dot)google(dot)com>, Hunter
(dave_h4(at)yahoo(dot)com) wrote:

> 4) I need my query to:
> a) count all rows where cust_id is in table A but *not* in table B
> AND *not* in table C

SELECT COUNT(*) FROM A
WHERE NOT EXISTS(SELECT 1 FROM B WHERE B.cust_id = A.cust_id)
AND NOT EXISTS(SELECT 1 FROM C WHERE C.cust_id = A.cust_id);

> b) display all emails where cust_id is in table A but *not* in table
> B AND *not* in table C

SELECT A.email FROM A
WHERE NOT EXISTS(SELECT 1 FROM B WHERE B.cust_id = A.cust_id)
AND NOT EXISTS(SELECT 1 FROM C WHERE C.cust_id = A.cust_id);

--
Regards,

Dave
======================================================
dwnoon(at)spamtrap(dot)ntlworld(dot)com (David W Noon)
Remove spam trap to reply via e-mail.
======================================================

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message edouard.boucher 2003-05-15 12:20:01 check with select
Previous Message Christoph Haller 2003-05-15 09:04:50 Re: Calculating Percentages