Re: [GENERAL] JOIN exclusion problem - Mailing list pgsql-general

From Chris Bitmead
Subject Re: [GENERAL] JOIN exclusion problem
Date
Msg-id 377B5C1D.50C2F68F@tech.com.au
Whole thread Raw
In response to JOIN exclusion problem  (Anja Speerforck <anja@damn.com>)
List pgsql-general
The problem is you've got two different result sets you need here. For
example, what would you expect to find in the k.name1 column if
k.kunden_nr is blank or null? The database doesn't know, and it can't
process the query without an answer.

You either need to break it into two separate queries or else make it
into a UNION. If it's a UNION you will need to specify explicity what to
put into k.name when joining with agenturen. I'm guessing that you want
it blank in such a case.


Anja Speerforck wrote:
>
> Thank you both for your replies.  Unfortunately, the AND solution doesn't
> work since individuals who have a value for ap.kunden_nr are not likely to
> have one for ap.agentur_nr -- they are two fairly distinct groups.  When I
> insert AND, the results are blank.
>
> Any other suggestions?
>
> At 16:23 01.07.99 +1000, you wrote:
> >Try using AND instead of OR.
> >
>
> >> 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"
>
> > 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
>                                    ^^
> You might wanna try an AND there.
>
> > ORDER BY nachname"

--
Chris Bitmead
mailto:chris@tech.com.au
http://www.techphoto.org - Photography News, Stuff that Matters

pgsql-general by date:

Previous
From: "Bryan White"
Date:
Subject: alter table add column is broken in 6.5
Next
From: "Colin Price (EML)"
Date:
Subject: RE: [GENERAL] 6.4.2 and 6.5 date usertype difference