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 > outer join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-04, 13:24
abe6162 abe6162 is offline
Registered User
 
Join Date: Feb 2004
Posts: 24
outer join

I need help with a outer join.

I have a table called raw_data_info ..
raw_data_id raw_data_name
1 net income
2 net assets


I have another table called raw_data
raw_data_id report_date amount
1 2/28/2000 50


I need to write a sql statement that will return the below

raw_data_name amount
net income 50
net assets

I want a blank for net assets.

Is this possible?

Last edited by abe6162; 12-09-04 at 13:27.
Reply With Quote
  #2 (permalink)  
Old 12-09-04, 14:16
lgaxiola lgaxiola is offline
Registered User
 
Join Date: Aug 2004
Posts: 99
It is possible:

select a.raw_data_name, b.amount
from
raw_data_info a, outer raw_data b
where
a.raw_data_id = b._raw_data_id

you just have to use the outer on the table that you want to get nulls from
Reply With Quote
  #3 (permalink)  
Old 12-10-04, 10:07
abe6162 abe6162 is offline
Registered User
 
Join Date: Feb 2004
Posts: 24
I am sorry. I left one column out. I didn't think it mattered, but I see it does now. I am doing this in Access.

The tables should be -- raw_data_info
raw_data_id -- raw_data_name
1 -- net income
2 -- net assets


I have another table called raw_data
raw_data_id -- report_date -- cmpy_num --- amount
1 -- 2/28/2000 -- 9999 -- 50
1 -- 2/28/2000 -- 8888 -- 100

I tired (but it didn't work) --

SELECT I.mdy_raw_data_name, D.amount
FROM raw_data_info AS I LEFT JOIN raw_data AS D ON I.raw_data_id=D.raw_data_id
WHERE (report_date=#2/28/1999# Or report_date Is Null)

Is there any way to return --
raw_data_name -- amount -- cmpy_num
net income -- 50 -- 9999
net assets -- -- 9999
net income -- 100 -- 8888
net assets -- -- 8888
Reply With Quote
  #4 (permalink)  
Old 12-10-04, 10:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select I.mdy_raw_data_name
     , D.amount
  from raw_data_info AS I 
left outer
  join raw_data AS D 
    on (
       I.raw_data_id = D.raw_data_id
   and iif(isnull(D.report_date)
          ,#2/28/1999#
          ,D.report_date) = #2/28/1999#
       )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-10-04, 11:11
abe6162 abe6162 is offline
Registered User
 
Join Date: Feb 2004
Posts: 24
Thank you so much!!
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