Unix Technical Forum

Left join pa on dal resulting in null

This is a discussion on Left join pa on dal resulting in null within the Pgsql General forums, part of the PostgreSQL category; --> Greetings, I have the following join, and in this join I am getting all of the data except that ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 06:27 AM
Ilene
 
Posts: n/a
Default Left join pa on dal resulting in null

Greetings,

I have the following join, and in this join I am getting all of the
data except that which joins the pa table to the dao table. When I
try to join it using a left join, i get all of the data except this
table. When I use a right join, I get nothing at all. If I make
this a seperate join to dal (rather than nested as it is) I have no
connection/path to the dao table because of the way that the postgres
optimizer works, and I have to use another alias, and I THINK that
the alias was causing other problems, but I'm not certain at the
moment. Can someone lead me to the the best way to tackle this problem?

The query currently looks like this:

SELECT
-- a bunch of columns here
dr.profile_id

FROM
dr,
da,
dal
LEFT JOIN ( doo
LEFT JOIN ( dao
LEFT JOIN pa
ON ( pa.dao_id = dao.dao_id )) -- the problem area is
here.
-
- There are cases where there are no related doo values set but
-
- I'm not sure how to write this better
ON ( doo.dao_id = dao.dao_id
OR pa.dal_id = doo.dal_id ))
ON ( dal.dal_id = doo.dal_id
OR dal.dal_id = pa.dal_id )

WHERE dr.dr_id = doo.dr_id
AND dr.dr_id = '1'
AND da.da_id = dal.da_id

ORDER BY da.name



Thank you in advance

Ilene

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com