Professional Documents
Culture Documents
View and Outer Join
View and Outer Join
View and Outer Join
Relational
VIEW here! schema studied
in class
Storage details
Hiding Information from Some Users
Some information should not be released
to all users
Students(sid, sname, gpa, age)
Customized and authorized data access
for different users or groups of users
Create a new table without gpa?
Extra overhead on coordination of updates: any
updates to one table have to be applied to the other
Extra overhead on space
Some Frequently Used Information
Frequently deriving course rosters from
Students(sid, sname, gpa, age)
CourseEnrolled(sid, cid, day)
Writingqueries to join the two tables
many times are tedious
Can we have a virtual table?
Roster(sname, cid, day), by joining the two tables
Students and CourseEnrolled
View
Create a virtual table from Students, only
include the sid, sname, age information
Students(sid, sname, gpa, age)
1
Inner Join
We have learned the following join:
SELECT S.sid, sname, bid
FROM Sailors S,Reserves R
WHERE S.sid = R.sid
1
Left Outer Join
Left Outer Join returns all matched rows
PLUS
all unmatched rows from the table on the left of the join clause
Use NULL in fields of non-matching tuples
1
SELECT S.sid, sname, bid
FROM Sailors S LEFT OUTER JOIN Reserves R
ON S.sid = R.sid
1
SELECT sid, B.bid, bname
FROM Reserves R RIGHT OUTER JOIN Boats B
ON R.bid = B.bid
1
Full Outer Join
Full Outer Join returns all (matched or
unmatched) rows from the tables on both sides
of the join clause
SELECT sid, B.bid, bname
FROM Reserves R FULL OUTER JOIN Boats B
ON R.bid = B.bid
1
SELECT sid, B.bid, bname
FROM Reserves R FULL OUTER JOIN Boats B
ON R.bid = B.bid
2
A Summary of Joins