SlideShare a Scribd company logo
SQL JOINS
By
Abdulla.B
21PCA530
What is SQL Join?
SQL JOINS are used to retrieve data from multiple
tables. A SQL JOIN is performed whenever two or more
tables are listed in a SQL statement.
List of SQL JOINS
❖ INNER JOIN
 OUTER JOIN
 LEFT JOIN OR LEFT OUTER JOIN
 RIGHT JOIN OR RIGHT OUTER JOIN
 FULL JOIN OR FULL OUTER JOIN
❖ CROSS JOIN
❖ NATURAL JOIN
❖ SELF JOIN
❖ EQUI JOIN
● EQUI JOIN is a simple SQL join.
● Uses the equal sign(=) as the comparison operator for the condition
● NON EQUI JOIN uses comparison operator other than the equal sign.
● The operators uses like >, <, >=, <= with the condition.
❖ NON EQUI JOIN
INNER JOIN
★ The INNER JOIN selects all rows from both participating tables as long as
there is a match between the columns.
★ An SQL INNER JOIN is same as JOIN clause, combining rows from two or
more tables.
Example : INNER JOIN
Name Age
Dany 20
Sam 23
Abd 21
Name Age
Guna 21
Sam 23
Raj 20
cricket
Football
SELECT * FROM cricket
INNER JOIN football ON
cricket.name=football.name;
Name Age Name Age
Sam 23 Sam 23
Output
cricket football
Sam,23
LEFT JOIN or LEFT OUTER JOIN
★ The SQL LEFT JOIN, joins two tables and fetches rows based on a
condition, which are matching in both the tables.
★ The unmatched rows will also be available from the table before the
JOIN clause.
Example : LEFT JOIN or LEFT OUTER JOIN
Name Age
Dany 20
Sam 23
Abd 21
Name Age
Guna 21
Sam 23
Raj 20
cricket
football
SELECT * FROM cricket
LEFT JOIN football ON
cricket.name=football.name;
Name Age Name Age
Dany 20 Sam 23
Sam 23 null null
Abd 21 null null
Output
cricket football
Dany
Sam
Abd
Sam
RIGHT JOIN or RIGHT OUTER JOIN
★ The SQL RIGHT JOIN, joins two tables and fetches rows based on a
condition, which are matching in both the tables.
★ The unmatched rows will also be available from the table written after
the JOIN clause.
Example : RIGHT JOIN or RIGHT OUTER JOIN
Name Age
Dany 20
Sam 23
Abd 21
Name Age
Guna 21
Sam 23
Raj 20
cricket
football
SELECT * FROM cricket
RIGHT JOIN football
ON
cricket.name=football.name;
Name Age Name Age
sam 23 Sam 23
null null Guna 23
null null Raj 20
Output
cricket football
Guna
Sam
Raj
Sam
❖ Combines the results of both left and right outer
joins.
❖ Returns all matched or unmatched rows.
❖ Includes tables on both sides of the join clause.
FULL OUTER JOIN
Example : FULL OUTER JOIN
Name Age
Dany 20
Sam 23
Abd 21
Name Age
Guna 21
Sam 23
Raj 20
cricket
football
SELECT * FROM cricket
FULL OUTER JOIN football ON
cricket.name=football.name;
Output
cricket football
Sam Guna
Raj
Name Age Name Age
Sam 23 Sam 23
Dany 20 null null
Abd 21 null null
null null Raj 20
null null Guna 21
Dany
Abd
CROSS JOIN
★ The CROSS JOIN is used to generate a paired combination of each row of
the first table with each row of the second table.
★ This join type is also known as cartesian join.
Example : CROSS JOIN
Meals
Omlet
Fried Egg
Sausage
Meals
SELECT *
FROM Meals
CROSS JOIN Drinks;
Output
Drinks
Drinks
Orange juice
Tea
Coffee
Meals Drinks
Omlet Orange Juice
Omlet Tea
Omlet Coffee
Fried egg Orange Juice
Fried egg Tea
Fried egg Coffee
Sausage Orange Juice
Sausage Tea
Sausage Coffee
Meals
Omlet
Fried egg
Sausage
Drinks
Orange juice
Tea
Coffee
NATURAL JOIN
★ The SQL NATURAL JOIN is a type of EQUI JOIN and is structured in such a
way that, columns with same name of associate tables will appear once
only.
★ The associated tables have one or more pairs of identically named
columns.
★ The columns must be the same data type.
★ Don’t use ON clause in a natural join.
Example : NATURAL JOIN
Name Age
Dany 20
Sam 23
Abd 21
cricket
SELECT *
FROM cricket
NATURAL JOIN football;
Name Age
Sam 23
Output
football
Name Age
Guna 21
Sam 23
Raj 20
Name Age
Dany 20
Sam 23
Abd 21
Name Age
Guna 21
Sam 23
Raj 20
SELF JOIN
★ A SQL Self join is a mechanism of joining a table to itself. You would use a
self join when you wanted to create a result set joining records in the
table with some other records from the same table.
★ SELF JOIN is not different type of join
★ It can be classified under any type of join
Inner Join
Outer Join (Right ,Left,Full)
Cross Join
Example : SELF JOIN
Employee ID Name Manager ID
1 Abdulla 3
2 Pragash 1
3 Sam Null
4 Guna 2
SELECT e.Name As Employee, m.Name As Manager
FROM emp_tbl e
LEFT JOIN emp_tbl m ON
e.ManagerID = m.EmployeeID
Employee Manager
Pragash Abdulla
Guna Pragash
Abdulla Sam
Sam Null
Output
Emp_tbl
Thank You

More Related Content

PPTX
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
PPTX
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
PPTX
PDF
SQL JOINS
PDF
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
PPTX
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
PPTX
Practical Joins Algorithms in database system
PPTX
SQL JOIN
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
SQL JOINS
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
Practical Joins Algorithms in database system
SQL JOIN

Similar to sql joins.pptx (20)

PPTX
SQL Joins.pptx
PPTX
sqljoins-220527115331-828e9932 (dee1).pptx
PPTX
V19 join method-c
PPTX
PRESENTATION........................pptx
PPT
PHP mysql Mysql joins
PPT
joins IN DATA BASE MANAGEMENT SYSTEMSppt
PDF
Sql joins
PPTX
Day-06-Joining presentation of SQL lecture form uni .pptx
ODT
Sql joins
PPTX
Joins (A JOIN clause is used to combine rows from two or more tables, based o...
PPTX
Querying_with_T-SQL_-_03 (1).pptx
PPTX
Querying_with_T-SQL_-_03.pptx
PDF
Lesson 6 - Relational Algebra.pdf
PDF
Advance database system(part 8)
PPTX
DBMS: Week 08 - Joins and Views in MySQL
PPT
SQL Joinning.Database
PPTX
View od dffmfmfmm,dm,f,dm,dfm,dddfdfsd,sd,sddf,df,ldf
PPTX
Sql(structured query language)
PDF
Tipos de Joins para consultas em banco de dados.pdf
SQL Joins.pptx
sqljoins-220527115331-828e9932 (dee1).pptx
V19 join method-c
PRESENTATION........................pptx
PHP mysql Mysql joins
joins IN DATA BASE MANAGEMENT SYSTEMSppt
Sql joins
Day-06-Joining presentation of SQL lecture form uni .pptx
Sql joins
Joins (A JOIN clause is used to combine rows from two or more tables, based o...
Querying_with_T-SQL_-_03 (1).pptx
Querying_with_T-SQL_-_03.pptx
Lesson 6 - Relational Algebra.pdf
Advance database system(part 8)
DBMS: Week 08 - Joins and Views in MySQL
SQL Joinning.Database
View od dffmfmfmm,dm,f,dm,dfm,dddfdfsd,sd,sddf,df,ldf
Sql(structured query language)
Tipos de Joins para consultas em banco de dados.pdf
Ad

Recently uploaded (20)

PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PDF
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
PPTX
importance of Data-Visualization-in-Data-Science. for mba studnts
PPTX
Managing Community Partner Relationships
PDF
Oracle OFSAA_ The Complete Guide to Transforming Financial Risk Management an...
PDF
Mega Projects Data Mega Projects Data
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked 2025}
PDF
How to run a consulting project- client discovery
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PDF
[EN] Industrial Machine Downtime Prediction
PDF
Microsoft Core Cloud Services powerpoint
PPTX
SAP 2 completion done . PRESENTATION.pptx
PPT
DATA COLLECTION METHODS-ppt for nursing research
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
Optimise Shopper Experiences with a Strong Data Estate.pdf
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
STERILIZATION AND DISINFECTION-1.ppthhhbx
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
importance of Data-Visualization-in-Data-Science. for mba studnts
Managing Community Partner Relationships
Oracle OFSAA_ The Complete Guide to Transforming Financial Risk Management an...
Mega Projects Data Mega Projects Data
Capcut Pro Crack For PC Latest Version {Fully Unlocked 2025}
How to run a consulting project- client discovery
Qualitative Qantitative and Mixed Methods.pptx
Data_Analytics_and_PowerBI_Presentation.pptx
[EN] Industrial Machine Downtime Prediction
Microsoft Core Cloud Services powerpoint
SAP 2 completion done . PRESENTATION.pptx
DATA COLLECTION METHODS-ppt for nursing research
climate analysis of Dhaka ,Banglades.pptx
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
Optimise Shopper Experiences with a Strong Data Estate.pdf
Ad

sql joins.pptx

  • 2. What is SQL Join? SQL JOINS are used to retrieve data from multiple tables. A SQL JOIN is performed whenever two or more tables are listed in a SQL statement.
  • 3. List of SQL JOINS ❖ INNER JOIN  OUTER JOIN  LEFT JOIN OR LEFT OUTER JOIN  RIGHT JOIN OR RIGHT OUTER JOIN  FULL JOIN OR FULL OUTER JOIN ❖ CROSS JOIN ❖ NATURAL JOIN ❖ SELF JOIN
  • 4. ❖ EQUI JOIN ● EQUI JOIN is a simple SQL join. ● Uses the equal sign(=) as the comparison operator for the condition ● NON EQUI JOIN uses comparison operator other than the equal sign. ● The operators uses like >, <, >=, <= with the condition. ❖ NON EQUI JOIN
  • 5. INNER JOIN ★ The INNER JOIN selects all rows from both participating tables as long as there is a match between the columns. ★ An SQL INNER JOIN is same as JOIN clause, combining rows from two or more tables.
  • 6. Example : INNER JOIN Name Age Dany 20 Sam 23 Abd 21 Name Age Guna 21 Sam 23 Raj 20 cricket Football SELECT * FROM cricket INNER JOIN football ON cricket.name=football.name; Name Age Name Age Sam 23 Sam 23 Output cricket football Sam,23
  • 7. LEFT JOIN or LEFT OUTER JOIN ★ The SQL LEFT JOIN, joins two tables and fetches rows based on a condition, which are matching in both the tables. ★ The unmatched rows will also be available from the table before the JOIN clause.
  • 8. Example : LEFT JOIN or LEFT OUTER JOIN Name Age Dany 20 Sam 23 Abd 21 Name Age Guna 21 Sam 23 Raj 20 cricket football SELECT * FROM cricket LEFT JOIN football ON cricket.name=football.name; Name Age Name Age Dany 20 Sam 23 Sam 23 null null Abd 21 null null Output cricket football Dany Sam Abd Sam
  • 9. RIGHT JOIN or RIGHT OUTER JOIN ★ The SQL RIGHT JOIN, joins two tables and fetches rows based on a condition, which are matching in both the tables. ★ The unmatched rows will also be available from the table written after the JOIN clause.
  • 10. Example : RIGHT JOIN or RIGHT OUTER JOIN Name Age Dany 20 Sam 23 Abd 21 Name Age Guna 21 Sam 23 Raj 20 cricket football SELECT * FROM cricket RIGHT JOIN football ON cricket.name=football.name; Name Age Name Age sam 23 Sam 23 null null Guna 23 null null Raj 20 Output cricket football Guna Sam Raj Sam
  • 11. ❖ Combines the results of both left and right outer joins. ❖ Returns all matched or unmatched rows. ❖ Includes tables on both sides of the join clause. FULL OUTER JOIN
  • 12. Example : FULL OUTER JOIN Name Age Dany 20 Sam 23 Abd 21 Name Age Guna 21 Sam 23 Raj 20 cricket football SELECT * FROM cricket FULL OUTER JOIN football ON cricket.name=football.name; Output cricket football Sam Guna Raj Name Age Name Age Sam 23 Sam 23 Dany 20 null null Abd 21 null null null null Raj 20 null null Guna 21 Dany Abd
  • 13. CROSS JOIN ★ The CROSS JOIN is used to generate a paired combination of each row of the first table with each row of the second table. ★ This join type is also known as cartesian join.
  • 14. Example : CROSS JOIN Meals Omlet Fried Egg Sausage Meals SELECT * FROM Meals CROSS JOIN Drinks; Output Drinks Drinks Orange juice Tea Coffee Meals Drinks Omlet Orange Juice Omlet Tea Omlet Coffee Fried egg Orange Juice Fried egg Tea Fried egg Coffee Sausage Orange Juice Sausage Tea Sausage Coffee Meals Omlet Fried egg Sausage Drinks Orange juice Tea Coffee
  • 15. NATURAL JOIN ★ The SQL NATURAL JOIN is a type of EQUI JOIN and is structured in such a way that, columns with same name of associate tables will appear once only. ★ The associated tables have one or more pairs of identically named columns. ★ The columns must be the same data type. ★ Don’t use ON clause in a natural join.
  • 16. Example : NATURAL JOIN Name Age Dany 20 Sam 23 Abd 21 cricket SELECT * FROM cricket NATURAL JOIN football; Name Age Sam 23 Output football Name Age Guna 21 Sam 23 Raj 20 Name Age Dany 20 Sam 23 Abd 21 Name Age Guna 21 Sam 23 Raj 20
  • 17. SELF JOIN ★ A SQL Self join is a mechanism of joining a table to itself. You would use a self join when you wanted to create a result set joining records in the table with some other records from the same table. ★ SELF JOIN is not different type of join ★ It can be classified under any type of join Inner Join Outer Join (Right ,Left,Full) Cross Join
  • 18. Example : SELF JOIN Employee ID Name Manager ID 1 Abdulla 3 2 Pragash 1 3 Sam Null 4 Guna 2 SELECT e.Name As Employee, m.Name As Manager FROM emp_tbl e LEFT JOIN emp_tbl m ON e.ManagerID = m.EmployeeID Employee Manager Pragash Abdulla Guna Pragash Abdulla Sam Sam Null Output Emp_tbl