SQL Join
SQL Join
DBMS
1
JOINS (by using the following relations – form_input & course)
2
NTURAL JOIN
SELECT * FROM form_input NATURAL JOIN course
This is a Join with one of the two identical columns eliminated and will
give an output that does not have any duplicate columns
It will retrieve data of all fields from both the tables on data equality of
identical columns (i.e. course code in both tables).
3
Output (NTURAL JOIN)
4
INNER JOIN
It will retrieve data of all fields from both the tables on data equality of
identical columns (i.e. course code in both tables).
5
Output (INNER JOIN)
6
Retrieve data for selected (some) fields from both tables
SELECT a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name FROM
form_input a INNER JOIN course b ON a.course_code=b.course_code
7
LEFT JOIN or LEFT OUTER JOIN
SELECT
a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name
FROM form_input a LEFT JOIN course b ON
a.course_code=b.course_code
OR
SELECT
a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name
FROM form_input a LEFT OUTER JOIN course b where
a.course_code=b.course_code
8
SELECT a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name FROM form_input a
LEFT JOIN course b ON a.course_code=b.course_code
(Output)
9
RIGHT JOIN or RIGHT OUTER JOIN
SELECT
a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name
FROM form_input a RIGHT JOIN course b ON
a.course_code=b.course_code
OR
SELECT
a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name
FROM form_input a RIGHT OUTER JOIN course b ON
a.course_code=b.course_code
10
SELECT a.form_no,a.stu_name,b.course_code,b.course_name,b.course_full_name FROM
form_input a RIGHT JOIN course b ON a.course_code=b.course_code
(Output)
11
References:
•North, Silbertz, Sudarshan, “Database Concepts”, Tata Mcgraw-hill Education
(India) Pvt. Ltd.
•Date C J, “An Introduction To Database System”, Addision Wesley
• Jain, Pillai, Singh “Introduction to Database Management”, BPB Publications.
12