If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Problems with right outer join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-06, 23:14
mabz mabz is offline
Registered User
 
Join Date: Apr 2004
Location: Wellington, NZ
Posts: 5
Problems with right outer join

Hiya,
I'm a little stuck with this one but it is probably my understanding off how outer joins are affected with more conditions that is the problem.

Basically this first query works and delivers all the records in office even if they have a null for sales area which is as I would have expected.

SELECT
offout.name as office_name,
grpout.name as sales_area
FROM
edw.t_office_all offout,
edw.t_group_all grpout
WHERE
offout.sales_area = grpout.id (+)

However when I try adding some correlation columns for extracting data from a warehouse I only get the office records that have a sales area specified. Office records that have null for sales area are not returned.

SELECT
offout.name as office_name,
grpout.name as sales_area
FROM
edw.t_office_all offout,
edw.t_group_all grpout
WHERE
offout.SNAPSHOT_TIME =
(
SELECT
max(offin.SNAPSHOT_TIME)
FROM
edw.t_office_all offin
WHERE
offin.id = offout.id
) AND
grpout.SNAPSHOT_TIME =
(
SELECT
max(grpin.SNAPSHOT_TIME)
FROM
edw.t_group_all grpin
WHERE
grpin.id = grpout.id

)
AND offout.sales_area = grpout.id (+)

Thanks for any help.

Cheers
Reply With Quote
  #2 (permalink)  
Old 03-02-06, 06:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select offout.name as office_name
     , grpout.name as sales_area
  from edw.t_office_all offout 
left outer
  join edw.t_group_all grpout 
    on offout.sales_area = grpout.id 
   and grpout.SNAPSHOT_TIME =
       ( select max(grpin.SNAPSHOT_TIME) 
           from edw.t_group_all grpin
          where grpin.id = grpout.id )
 where offout.SNAPSHOT_TIME 
     = ( select max(offin.SNAPSHOT_TIME) 
           from edw.t_office_all offin
          where offin.id = offout.id )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On