INTRODUCTION TO SQL
WHAT ARE JOINS IN SQL?
TYPES OF JOINS
FAQs ABOUT JOINS
www.edureka.co/mysql-dba
www.edureka.co/mysql-dba
2.5 x 1018 Bytes
www.edureka.co/mysql-dba
SQLisastandardlanguagewhichstandsforStructuredQueryLanguage.SQListhecoreofrelationaldatabaseandis
usedforaccessingandmanagingdatabase.
IntroductiontoSQL
www.edureka.co/mysql-dba
Core of Relational
Databases
Database Administrators
www.edureka.co/mysql-dba
JOINSinSQLarecommandswhichareusedtocombinerowsfromtwoormoretables,basedonarelatedcolumn
betweenthosetables. Theyarepredominantlyusedwhenauseristryingtoextractdatafromtableswhichhaveone-
to-manyormany-to-manyrelationshipsbetweenthem.
WhatareJoinsinSQL?
www.edureka.co/mysql-dba
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
INNER JOIN LEFT JOIN
RIGHT JOIN FULL JOIN
www.edureka.co/mysql-dba
TYPES OF
JOINS
INNER JOIN
Thistypeofjoinreturnsthoserecordswhichhavematchingvaluesinboth
tables.So,ifyouperformanINNERJOINoperationbetweentheEmployeetable
andtheProjectstable,allthetupleswhichhavematchingvaluesinboththe
tableswillbegivenasoutput.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
INNER JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
INNER JOIN LEFT JOIN
RIGHT JOIN FULL JOIN
www.edureka.co/mysql-dba
TYPES OF
JOINS
LEFT JOIN
TheLEFTJOINortheLEFTOUTERJOIN returnsalltherecordsfromthelefttable
andalsothoserecordswhichsatisfyaconditionfromtherighttable.Also,for
therecordshavingnomatchingvaluesintherighttable,theoutputorthe
result-setwillcontaintheNULLvalues.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
LEFT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 LEFT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName;
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
INNER JOIN LEFT JOIN
RIGHT JOIN FULL JOIN
www.edureka.co/mysql-dba
TYPES OF
JOINS
RIGHT JOIN
TheRIGHTJOINortheRIGHTOUTERJOIN returnsalltherecordsfromtheright
tableandalsothoserecordswhichsatisfyaconditionfromthelefttable.Also,
fortherecordshavingnomatchingvaluesinthelefttable,theoutputorthe
result-setwillcontaintheNULLvalues.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
RIGHT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 RIGHT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName;
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
INNER JOIN LEFT JOIN
RIGHT JOIN FULL JOIN
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
FULL JOIN
FullJoinortheFullOuterJoinreturnsallthoserecordswhicheitherhavea
matchintheleft(Table1)ortheright(Table2)table.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
FULL JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
www.edureka.co/mysql-dba
TYPES OF
JOINS
www.edureka.co
INNER JOIN LEFT JOIN
RIGHT JOIN FULL JOIN
www.edureka.co/mysql-dba
www.edureka.co/mysql-dba
What is a Natural Join and in which situations
is a Natural Join used?
www.edureka.co/mysql-dba
What is a Natural Join and in which situations is a Natural
Join used?
www.edureka.co/mysql-dba
Output when you apply
INNER JOIN
Output when you apply
NATURAL JOIN
How to map many-to-many relationships
using joins?
www.edureka.co/mysql-dba
How to map many-to-many relationships using joins?
www.edureka.co/mysql-dba
Projects Technologies Projects_to_Technologies
2JOIN statements
What is a Hash Join?
www.edureka.co/mysql-dba
What is a Hash Join?
www.edureka.co/mysql-dba
Hash Joins are also a type of joins which are used to join large tables or in an instance,
where the user wants most of the joined table rows.
The Hash Join algorithm is a two-step algorithm.
Build Phase Probe Phase
What is Self & Cross Join?
www.edureka.co/mysql-dba
What is Self & Cross Join?
www.edureka.co/mysql-dba
SELF JOIN in is a join of a table to itself. This implies that each row in a table is joined
with itself.
The CROSS JOIN is a type of join in which a join clause is applied to each row of a table to
every row of the other table. Also, when the WHERE condition is used, this type of JOIN
behaves as an INNER JOIN, and when the WHERE condition is not present, it behaves like a
CARTESIAN product..
Self Join
Cross Join
How to perform JOIN operation on three
tables?
www.edureka.co/mysql-dba
How to perform JOIN operation on three tables?
www.edureka.co/mysql-dba
To perform a JOIN operation on 3 tables, you
need to use 2 JOIN statements.
www.edureka.co/mysql-dba

SQL Joins With Examples | Edureka