I am trying to understand Oracle join syntax of using (+) to join two tables.
Could someon show me how would this query would look if it was converted to use the standard join syntax?
select p1.product_id, p1.product_name, p2.product_code, (decode(p3.product_type, null, 'N/A',p3.product_type) as product_type
from products p1, product_descriptions p2, product_descriptions p3
where p1.product_id=p2.product_id
and p2.product_age=p3.product_age(+)
and p2.product_type=p3.product_type(+)
and p3.status(+)='VALID'
Something like this:
The
where p1.product_id=p2.product_idis a normal inner join betweenp1andp2. The others are outer joins; the way it’s written looks like a mix of left and right outer joins, but sinceand p2.product_age=p3.product_age(+)is the same asand p3.product_age(+)=p2.product_agethen it isn’t really; it’s a fairly straightforward left outer join between the product of thep1/p2join andp3.As an aside, I’m not a fan of aliases like
p1,p2andp3as they are not descriptive, and it’s easy to get lost when you do this in more complicated queries. I’m not alone.I’m not sure you even need the outer join, but it rather depends on the data. If
product_ageandproduct_typeis unique then you couldcasethep2.status; if it isn’t then you’re probably assuming that only oneproduct_age/product_typerow can beVALID, otherwise you’d get duplicates. Just musing about what you’re trying to do…