Monday, February 20, 2012

Join multiple tables

I'm trying to join 3 tables:

EMPLOYEE - empid

SKILL - empid, skillid, skill

SKILLOPTIONS - skillid, option

An EMPLOYEE will always have at least 1 SKILL but each SKILL may or may not have any SKILLOPTIONS. I do an INNER JOIN:

EMPLOYEE->SKILL->SKILLOPTIONS but I only get a record if there is actually a SKILLOPTION. I want a record with EMPLOYEE and SKILL even if there are no SKILLOPTIONS. In Oracle it is the (+) symbol in the WHERE statement in conjunction with the JOIN. Am new to this so I'm sure the answer is simple.

Try left join, like

EMPLOYEE left join SKILL on EMPLOYEE.empid= SKILL.empid

left join SKILLOPTIONS on SKILLOPTIONS left join SKILL on SKILLOPTIONS=skillid=SKILL.skillid

|||

Biff:

I think that if you would associate the Oracle + operator only with the SKILLOPTIONS table that the join that you want is similar to:

select <selectList>
from EMPLOYEE
inner join SKILL
on EMPLOYEE.empid = SKILL.empid
left outer join SKILLOPTIONS
on SKILL.skillid = SKILLOPTIONS.skillid

Dave

No comments:

Post a Comment