Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15

QUERY

PROCESSING cont.

IT1 – DATABASE MANAGEMENT SYSTEM


WEEK 8 – QUERY PROCESSING: JOINS

JOINS
• Lets you combine columns from two or more tables
into a single result set.
• To join data from two tables, you code the names
of two tables in the FROM clause along with the
JOIN keyword and ON phrase that specifies the join
condition.
Join condition. Indicates how the two tables should be
compared.

IM101 – ADVANCED DATABASE SYSTEMS 3


WEEK 7 – QUERY PROCESSING

SYNTAX
SELECT select_list
FROM table_1
JOIN_TYPE table_2
ON join_condition

IM101 – ADVANCED DATABASE SYSTEMS 4


WEEK 7 – QUERY PROCESSING

INNER JOIN
• Join only rows that satisfy the join condition.

Syntax:
SELECT select_list
FROM table_1
INNER JOIN table_2
ON join_condition

IM101 – ADVANCED DATABASE SYSTEMS 5


WEEK 7 – QUERY PROCESSING

INNER JOIN
Student_tbl
Student_Number Student_Name Section_id
00-0001 A. Dela Cruz 01
00-0002 B. Cruz 02
00-0003 C. Reyes 04

Section_tbl
Section_id Section
01 A - 001
02 B - 001
03 C - 001

IM101 – ADVANCED DATABASE SYSTEMS 6


WEEK 7 – QUERY PROCESSING

INNER JOIN
SELECT Student_Number, Student_Name, Section
FROM Student_tbl
INNER JOIN Section_tbl
ON Student_tbl.Section_id = Section_tbl.Section_id

Result
Student_Number Student_Name Section
00-0001 A. Dela Cruz A-001
00-0002 B. Cruz B-001

IM101 – ADVANCED DATABASE SYSTEMS 7


WEEK 7 – QUERY PROCESSING

INNER JOIN MORE THAT TWO


TABLES
Syntax:
SELECT select_list
FROM table_1
INNER JOIN table_2
ON join_condition
INNER JOIN table_3
ON join_conditon

IM101 – ADVANCED DATABASE SYSTEMS 8


WEEK 7 – QUERY PROCESSING

INNER JOIN MORE THAT TWO


TABLES
Student_tbl
Student_Number Student_Name Section_id Course_id
00-0001 A. Dela Cruz 01 1
00-0002 B. Cruz 02 1
00-0003 C. Reyes 04 3

Section_tbl Course_tbl
Section_id Section Course_id Course
01 A - 001 1 BSIT
02 B - 001 2 BSEE
03 C - 001 3 BSIE

IM101 – ADVANCED DATABASE SYSTEMS 9


WEEK 7 – QUERY PROCESSING

INNER JOIN MORE THAT TWO


TABLES
SELECT Student_Number, Student_Name, Section, Course
FROM Student_tbl
INNER JOIN Section_tbl
ON Student_tbl.Section_id = Section_tbl.Section_id
INNER JOIN Course_tbl
ON Student_tbl.Course_id = Course_tbl.Course_id
Result
Student_Number Student_Name Section Course
00-0001 A. Dela Cruz A-001 BSIT
00-0002 B. Cruz B-001 BSIT
00-003 C. Reyes Null BSIE

IM101 – ADVANCED DATABASE SYSTEMS 10


WEEK 7 – QUERY PROCESSING

OUTER JOIN
• Returns all of the rows from one or both tables
involved in the join, regardless of whether the join
condition is true.
• Left Join. The result set includes all the rows from the first,
or left table.
• Right Join. The result set includes all the rows from the
second, or right table.
• Full Join. The result set includes all the rows from both
tables.

IM101 – ADVANCED DATABASE SYSTEMS 11


WEEK 7 – QUERY PROCESSING

OUTER JOIN

IM101 – ADVANCED DATABASE SYSTEMS 12


WEEK 7 – QUERY PROCESSING

USING LEFT JOIN

IM101 – ADVANCED DATABASE SYSTEMS 13


WEEK 7 – QUERY PROCESSING

USING RIGHT JOIN

IM101 – ADVANCED DATABASE SYSTEMS 14


WEEK 7 – QUERY PROCESSING

USING FULL JOIN

IM101 – ADVANCED DATABASE SYSTEMS 15


WEEK 5 – MANAGING DATABASE STORAGE STRUCTURE AND USER
SECURITY

THE END…

IM101 – ADVANCED DATABASE SYSTEMS 16

You might also like