Left Join 3 tables

From: dave_h4(at)yahoo(dot)com (Hunter)
To: pgsql-sql(at)postgresql(dot)org
Subject: Left Join 3 tables
Date: 2003-05-14 17:35:19
Message-ID: 27ad91d2.0305140935.4fdec226@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Group -

1) I have 3 tables: A, B and C
2) Each table has an unqiue associative field called cust_id
3) The cust_id HAS to be in table A, the cust_id *could* be in table
B, and the cust_id *could* be in table C
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
b) display all emails where cust_id is in table A but *not* in table
B AND *not* in table C

Here's some of my queries of what I have:

This one is close I think:

select distinct A.email from A
left join A as ics on ics.custid = A.custid
left join B on B.custid = A.custid
left join C on C.custid = A.custid
where ics.custid <> A.custid;

THANK YOU!

dave

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2003-05-14 18:01:51 Re: Type coercion on column in a query
Previous Message Tom Lane 2003-05-14 17:08:23 Re: Followup from yesterday's PL/pgSQL fun...