0% found this document useful (0 votes)
5 views7 pages

JOINS

The document explains the concept of joins in databases, which are used to retrieve data from two or more related tables based on common values. It outlines various types of joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN, providing syntax and examples for each. Additionally, it illustrates the results of these joins using sample tables 'KFC' and 'Subway'.

Uploaded by

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

JOINS

The document explains the concept of joins in databases, which are used to retrieve data from two or more related tables based on common values. It outlines various types of joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN, providing syntax and examples for each. Additionally, it illustrates the results of these joins using sample tables 'KFC' and 'Subway'.

Uploaded by

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

JOINS

DEFINITION :-
 In database, join is used to retrieve data from two or more logically related
tables based on common set of values.
 These values are usually the same column name and datatype that appear in both
the participating tables in Join.

General Syntax :-

SELECT columnname(s)
FROM table1
JOIN_TYPE table2
ON table1.column = table2.column;
Types of Joins :-
There are different types of joins available in SQL. Some are :-
 INNER JOIN
 SELF JOIN
 NATURAL JOIN
 FULL JOIN
 LEFT JOIN / LEFT OUTER JOIN
 RIGHT JOIN / RIGHT OUTER JOIN etc.,
Venn diagram representation for joins
1.Inner join :-
 It selects or retrieve only the matching records from both tables, only if
they meet the conditions specified in the “ON” clause.
Syntax :-
SELECT columnname(s) FROM table1 INNER JOIN table2
ON table1.column = table2.column;
Example, consider the two given tables, table1 “KFC” and table 2 “Subway”.

Food Price Food Quantity


Pizza 100
Pizza 199
Burger 200
Burger 200
Sandwich 150
Sandwic 180 French_fr 50
h ies
Cake 120 Cake 120
Roll 90 Cream 50
Bun
For the above given tables, if we perform inner join, then the command and output will be

SELECT Output :
kfc.food,kfc.price,subway.quantity Food Price Quantit
FROM kfc y
INNER JOIN Subway Pizza 199 100
ON kfc.food = subway.food;
2. Left Join / Left Outer join :-
 It retrieves the matching records from both tables and the rowsBurger
from table1(left 200 200
table) even if they are unmatched.
(Simply it performs Inner Join + Left table rows)
Syntax :- Sandwic 180 150
SELECT columnname(s) FROM table1 LEFT JOIN table2
ON table1.column = table2.column;
h
Command and output :- Cake 120 120
SELECT kfc.food,kfc.price,subway.quantity
FROM kfc
LEFT JOIN Subway
ON kfc.food = subway.food;
3. Right Join / Right Outer join :-
 It retrieves the matching records from both tables and the rows from
table2(right table) even if they are unmatched. (Simply it performs Inner Join +
Right table rows)

Syntax :-
SELECT columnname(s) FROM table1 RIGHT JOIN table2
ON table1.column = table2.column;

Command and output :-


SELECT kfc.food, subway.food,subway.quantity
FROM kfc
RIGHT JOIN Subway
ON kfc.food = subway.food;
Output :-

Food Food Quantity


Pizza Pizza 100
Burger Burger 200
Sanwich Sandwich 150
Cake French_frie 50
s
Cake 120
Cream Bun 50

4. Full Join :-
 It retrieves all the records from both the tables.

Syntax :-
SELECT columnname(s) FROM table1 FULL JOIN table2
ON table1.column = table2.column;
Command and output :-

SELECT kfc.food, kfc.price,subway.food,subway.quantity


FROM kfc
FULL JOIN Subway
ON kfc.food = subway.food;

Food Price Food Quantity


Pizza 199 Pizza 100
Burger 200 Burger 200
Sandwich 180 Sandwich 150
Cake 120 French_frie 50
s
Roll 50 Cake 120
Cream_Bun 50

You might also like