Lecture 4 - Joins Flashcards
What is an inner join?
A condition that matches FK and PKs in SQL?
What is EQUIJOIN?
it is another name for inner join
Example of inner / equi join.
SELECT firstname , lastname, address
FROM (EMPLOYEE JOIN DEPARTMENT ON Dno = Dnumber)
Unusual syntax example of inner join
SELECT Fname, Lname, Address
FROM EMPLOYEE, DEPARTMENT
WHERE Dname = ‘Research’ %selection condition
AND DNO = DNUMBER; %equi-join condition
Inner join only works when …
there is a matching tuple i.e. FK is not null
What is an outer join?
joining on attributes but includes NULLs
What is an outer left join?
LEFT OUTER JOIN (LR LEFT OUTER JOIN RR)
- Every tuple in the left relation LR must appear in result
- If no matching tuple exists, just add NULL values for attributes of
right relation RR
What is an outer right join?
RIGHT OUTER JOIN (LR RIGHT OUTER JOIN RR)
- Every tuple in the right relation RR must appear in result
- `If no matching tuple exists, just add NULL values for attributes of left
relation LR
Example of left outer join?
SELECT E.Lname, S.Lname
FROM (EMPLOYEE AS E LEFT OUTER JOIN EMPLOYEE AS S
ON E.Super_SSN = S.SSN)
What is this doing:
SELECT E.Fname, E.Minit, E.Lname, D.Dname
FROM EMPLOYEE AS E LEFT OUTER JOIN DEPARTMENT AS D
ON E.SSN = D.MGR_SSN
We are getting all employees and what department they’re in charge of if any (NULL if not)
With joins, do NULL values represent uncertainity or certainity?
Certainity, we know the context i.e. employee has no supervisor or employee is not a department manager