0% found this document useful (0 votes)
7 views12 pages

SQL Join

The document discusses different types of joins in SQL including natural join, inner join, left join, and right join. Natural join and inner join return rows that match on identical columns between two tables. Left join and right join also return non-matching rows from the left or right table respectively.

Uploaded by

lossno26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

SQL Join

The document discusses different types of joins in SQL including natural join, inner join, left join, and right join. Natural join and inner join return rows that match on identical columns between two tables. Left join and right join also return non-matching rows from the left or right table respectively.

Uploaded by

lossno26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

SQL (JOINs)

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

SELECT * FROM form_input INNER JOIN course WHERE


form_input.course_code= course.course_code
OR
SELECT * FROM form_input INNER JOIN course ON form_input
.course_code= course.course_code

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

You might also like