morechocolate
Technical User
I have two tables with data that looks something like the following:
LOAN_NO AMOUNT1 AMOUNT2
200 152.60 4569.00
203 1652.00 7896.00
205 2589.36 159.62
LOAN_NO EMPLOYEE POSITION START_DATE END_DATE
200 Chris J. Accountant 2001-02-11 NULL
200 Ed P. Analyst 1998-03-04 NULL
203 Kelly M. Analyst 1999-08-22 NULL
205 Jake H. Accountant 1985-02-03 NULL
206 Pat W. Accountant 1986-05-18 2004-01-31
I want all the loan numbers from the first table and from the second table I want all the accountants. Even if there is no accountant in the second table, I want the amount for all the loans in the first table.
When I do a left outer join like the following, I do not get Loan Number 203. I am having serious brain freeze on how to get it. It seems to be happening because the loan does exist in table two, but because of the accoutant criteria I am not getting it.
select t1.loan_number,t1.amount1, t1.amount2
from table1 t1
left outer join table2 t2 on
t1.loan = t2.loan
where (t2.postition = 'accountant' and
t2.end_date is null) or
t2.loan is null /* this does not do anything because loan number 203 is in table 2 */
Thanks
mc
LOAN_NO AMOUNT1 AMOUNT2
200 152.60 4569.00
203 1652.00 7896.00
205 2589.36 159.62
LOAN_NO EMPLOYEE POSITION START_DATE END_DATE
200 Chris J. Accountant 2001-02-11 NULL
200 Ed P. Analyst 1998-03-04 NULL
203 Kelly M. Analyst 1999-08-22 NULL
205 Jake H. Accountant 1985-02-03 NULL
206 Pat W. Accountant 1986-05-18 2004-01-31
I want all the loan numbers from the first table and from the second table I want all the accountants. Even if there is no accountant in the second table, I want the amount for all the loans in the first table.
When I do a left outer join like the following, I do not get Loan Number 203. I am having serious brain freeze on how to get it. It seems to be happening because the loan does exist in table two, but because of the accoutant criteria I am not getting it.
select t1.loan_number,t1.amount1, t1.amount2
from table1 t1
left outer join table2 t2 on
t1.loan = t2.loan
where (t2.postition = 'accountant' and
t2.end_date is null) or
t2.loan is null /* this does not do anything because loan number 203 is in table 2 */
Thanks
mc