CH 6
CH 6
1
Objectives
Database Design
Performing joining
Procedures
Triggers
2
SQL JOIN
• LEFT (OUTER) JOIN: Returns all records from the left table, and the matched
records from the right table
• RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched
records from the left table
• FULL (OUTER) JOIN: Returns all records when there is a match in either left or
right table
3
Cont.’
4
INNER JOIN
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
5
Cont.’
6
Cont.’
7
Cont.’
FROM Orders
8
LEFT JOIN
• The LEFT JOIN keyword returns all records from the left table
(table1), and the matched records from the right table (table2).
The result is NULL from the right side, if there is no match.
• SELECT column_name(s)
FROM table1
LEFT JOIN table2
Note: In some databases LEFT JOIN is called LEFT OUTER JOIN.
ON table1.column_name = table2.column_name;
9
Cont.’
FROM Customer
10
RIGHT JOIN
• The RIGHT JOIN keyword returns all records from the right table
(table2), and the matched records from the left table (table1). The
result is NULL from the left side, when there is no match.
• SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
11
Cont.’
FROM Orders
12
Any Questions?
13