Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outer join with multiple conditions

Status
Not open for further replies.

meghaAgrawal

Programmer
May 20, 2004
14
US
I have unit and tenant tables. One unit can have 0 or 1 tenant. I have to extract all units with either no tenants or with tenants of particular status codes like 'Past' and 'Future'. I cannot apply OR operator on tenant.status as tenant is optional table for join.

Following query doesn't bring correct data. And I need to write something like this. What is the alternative? I am on Oracle 8i.

select count(u.code)
from
unit u, tenant t
where t.hunit (+) = u.hmy
and (t.status (+) = 'Past' or t.status (+) = 'Future')
and nvl(u.excluded, 0) = 0

Thanks

-megha
 
I think I figured it out:

select count(u.scode)
from unit u,
(select * from tenant where status in ('Past', 'Future')) t
where u.hmy = t.hunit (+) and nvl(u.exclude, 0) = 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top