Re: [GENERAL] JOIN exclusion problem

From: Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] JOIN exclusion problem
Date: 1999-07-01 10:26:46
Message-ID: v04020a03b3a0f2ddb4db@[128.40.242.190]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm not sure that I understand exactly what you are trying to do. I'm
guessing (and I mean guessing) that the tables are something like:

ansprechpartner: private owner
kunden: client
agenturen: estate agent

So are you trying to get is get details on all properties both privately
rented and rented via an agency?

I think a \d of all the tables involved would be useful to make sense of it
all.

In the interim though, if you only what unique combinations of ag.name1 and
k.name1 you could try:

SELECT DISTINCT k.name1, ag.name1
FROM ansprechpartner ap, kunden k, agenturen ag
WHERE ap.kunden_nr = k.kunden_nr OR ap.agentur_nr = ag.agentur_nr;

But somethings tells me that's not what you actually wanted!

>Hello,
>
>I'm trying to join three tables, where I need only one piece of data from
>two of the tables. The code I wrote is:
>
>SELECT apartner_nr, ap.anrede, ap.vorname, ap.nachname, ap.telefon, ap.fax,
>ap.email, ap.kunden_nr, k.name1, ap.agentur_nr, ag.name1
>FROM ansprechpartner ap, kunden k, agenturen ag
>WHERE ap.kunden_nr = k.kunden_nr OR ap.agentur_nr = ag.agentur_nr
>ORDER BY nachname"
>
>The problem is that each row from each table is combined with each row of
>the other tables. I know the code is wrong, but I don't know how to write
>it so that the results show only the actual value of ag.name1 and k.name1,
>and not all of the possible combinations.
>
>Is there a way of limiting how the rows are built up? Pardon for novice
>nature of this question...
>
>Thanks in advance,
>
>Anja
+-------------------------+--------------------------------------+
| Stuart Rison | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street |
| Tel. (0171) 878 4041 | London, W1P 8BT, UNITED KINGDOM. |
| Fax. (0171) 878 4040 | stuart(at)ludwig(dot)ucl(dot)ac(dot)uk |
+-------------------------+--------------------------------------+

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Rison 1999-07-01 12:11:07 limits of float8
Previous Message Anja Speerforck 1999-07-01 08:46:08 Re: [GENERAL] JOIN exclusion problem