SlideShare a Scribd company logo
MySQL JoinsMySQL Joins
MySQL Joins OverviewMySQL Joins Overview
 MySQL Join is used to join the records from twoMySQL Join is used to join the records from two
tables using join clause.tables using join clause.
 The Join Clause return you the set of records fromThe Join Clause return you the set of records from
both table on the basis of common column.both table on the basis of common column.
MySQL Join TypesMySQL Join Types
 MySQLMySQL Inner JoinInner Join
 MySQL Equi JoinMySQL Equi Join
 MySQL Natural JoinMySQL Natural Join
 MySQL Cross JoinMySQL Cross Join
 MySQL Outer JoinMySQL Outer Join
 Left Outer JoinLeft Outer Join
 Right Outer JoinRight Outer Join
 Self JoinSelf Join
 Inner joinInner join produces only the set of records that produces only the set of records that
match in both Table A and Table B.match in both Table A and Table B.
MySQL Inner JoinMySQL Inner Join
 The INNER JOIN keyword returns rows when thereThe INNER JOIN keyword returns rows when there
is at least one match in both tables.is at least one match in both tables.
 If there are rows in "Persons" that do not haveIf there are rows in "Persons" that do not have
matches in "Orders", those rows will NOT be listed.matches in "Orders", those rows will NOT be listed.
 Example:Example:
 SELECT Persons.LastName,SELECT Persons.LastName,
Persons.FirstName, Orders.OrderNoPersons.FirstName, Orders.OrderNo
FROM Persons INNER JOIN OrdersFROM Persons INNER JOIN Orders
ON Persons.P_Id = Orders.P_IdON Persons.P_Id = Orders.P_Id
ORDER BY Persons.LastNameORDER BY Persons.LastName
(Contd:)MySQL Inner JoinMySQL Inner Join
MySQL Outer JoinMySQL Outer Join
 MySQL Outer Join return you the set of all matchingMySQL Outer Join return you the set of all matching
records from both table.records from both table.
 The Outer Join does not requires each records to beThe Outer Join does not requires each records to be
matched in both the tables.matched in both the tables.
 MySQL Outer Join is categorized into two groups.MySQL Outer Join is categorized into two groups.
 MySQL Left Outer JoinMySQL Left Outer Join
 MySQL Right Outer JoinMySQL Right Outer Join
MySQL Left Outer JoinMySQL Left Outer Join
 Left outer joinLeft outer join produces a complete set of records produces a complete set of records
from Table A, with the matching records (wherefrom Table A, with the matching records (where
available) in Table B. If there is no match, the right sideavailable) in Table B. If there is no match, the right side
will contain null.will contain null.
MySQL Left Outer JoinMySQL Left Outer Join
 The left join is used in case of need to return all rowsThe left join is used in case of need to return all rows
from the left table, even if the right table doesn't havefrom the left table, even if the right table doesn't have
any match.any match.
 Example:Example:
 SELECT Persons.LastName,SELECT Persons.LastName,
Persons.FirstName, Orders.OrderNoPersons.FirstName, Orders.OrderNo
FROM Persons LEFT JOIN OrdersFROM Persons LEFT JOIN Orders
ON Persons.P_Id=Orders.P_IdON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastNameORDER BY Persons.LastName
(Contd:)
MySQL Right Outer JoinMySQL Right Outer Join
 The right join is used in case of need to return allThe right join is used in case of need to return all
rows from the right table, even if the left tablerows from the right table, even if the left table
doesn't have any match.doesn't have any match.
 Example:Example:
 SELECT Persons.LastName,Persons.FirstName,SELECT Persons.LastName,Persons.FirstName,
Orders.OrderNoOrders.OrderNo
FROM Persons RIGHT JOIN OrdersFROM Persons RIGHT JOIN Orders
ON Persons.P_Id = Orders.P_IdON Persons.P_Id = Orders.P_Id
ORDER BY Persons.LastNameORDER BY Persons.LastName
MySQL Cross JoinMySQL Cross Join
 Cross Join is also called Cartesian Product Join.Cross Join is also called Cartesian Product Join.
 The Cross Join in SQL return you  a result table inThe Cross Join in SQL return you  a result table in
which each row from the first table is combined withwhich each row from the first table is combined with
each rows from the second table.each rows from the second table.
MySQL Cross JoinMySQL Cross Join
 In other words, you can say it is the crossIn other words, you can say it is the cross
multiplication of number of rows in each table.multiplication of number of rows in each table. 
 Example:Example:
 SELECT * FROM persons cross join orders;SELECT * FROM persons cross join orders;
(Contd:)
MySQL Equi JoinMySQL Equi Join
 Equi Join is a classified type of Inner Join in Mysql.Equi Join is a classified type of Inner Join in Mysql.
 Equi Join is used to combine records from two tableEqui Join is used to combine records from two table
based on the common column exists in both table.based on the common column exists in both table.
 The Equi Join returns you only those records whichThe Equi Join returns you only those records which
are available in both table on the basis of commonare available in both table on the basis of common
primary field name.primary field name.
 Example:Example:
 SELECT persons.firstname,orders.orderNoSELECT persons.firstname,orders.orderNo
FROM persons, ordersFROM persons, orders
WHERE persons.p_id = orders.p_id;WHERE persons.p_id = orders.p_id;
MySQL Natural JoinMySQL Natural Join
 MySQL Natural Join is a specialization of equi-joins.MySQL Natural Join is a specialization of equi-joins.
 The join compares all columns in both tables thatThe join compares all columns in both tables that
have the same column-name in both tables that havehave the same column-name in both tables that have
column name in the joined table.column name in the joined table.
 Example:Example:
 SELECT persons.firstname, orders.orderNoSELECT persons.firstname, orders.orderNo
FROM persons NATURAL JOIN orders;FROM persons NATURAL JOIN orders;
MySQL Self JoinMySQL Self Join
 These join allow you to retrieve related recordsThese join allow you to retrieve related records
from the same table. from the same table. 
 The most common case where you'd use a self-join isThe most common case where you'd use a self-join is
when you have a table that references itself.when you have a table that references itself.
 Example:Example:
 SELECT m.name as "Manager", p.name asSELECT m.name as "Manager", p.name as
"Employee“"Employee“
FROM employee m, employee pFROM employee m, employee p
WHERE m.emp_id = p.manager_id;WHERE m.emp_id = p.manager_id;
Ad

More Related Content

What's hot (20)

Dbms normalization
Dbms normalizationDbms normalization
Dbms normalization
Pratik Devmurari
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Manipulating data
Manipulating dataManipulating data
Manipulating data
Syed Zaid Irshad
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
Bwsrang Basumatary
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
SanSan149
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
mysql content
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
Mysql
MysqlMysql
Mysql
TSUBHASHRI
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of join
raj upadhyay
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Normal forms
Normal formsNormal forms
Normal forms
Samuel Igbanogu
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
Nargis Ehsan
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
SanSan149
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of join
raj upadhyay
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
Nargis Ehsan
 

Viewers also liked (10)

MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
Jamshid Hashimi
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
Mathan Mathan K
 
Mysql count
Mysql countMysql count
Mysql count
Ritwik Das
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
Vineet Kumar Saini
 
Database normalization
Database normalizationDatabase normalization
Database normalization
Jignesh Jain
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQL
ZendCon
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 
程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍
Jinrong Ye
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
tameemyousaf
 
Database normalization
Database normalizationDatabase normalization
Database normalization
Jignesh Jain
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQL
ZendCon
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 
程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍
Jinrong Ye
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
tameemyousaf
 
Ad

Similar to PHP mysql Mysql joins (20)

JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
ArunkumarT51
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptx
KrishnansuSenapati
 
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjjKailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
kailasmanoj
 
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbjKailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
kailasmanoj
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
Balqees Al.Mubarak
 
Sql slid
Sql slidSql slid
Sql slid
pacatarpit
 
Joins.ppt
Joins.pptJoins.ppt
Joins.ppt
UmangThakkar26
 
3)12th_L8_Join-Set-Operations.pdf
3)12th_L8_Join-Set-Operations.pdf3)12th_L8_Join-Set-Operations.pdf
3)12th_L8_Join-Set-Operations.pdf
AdityavardhanSingh15
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
SQL report
SQL reportSQL report
SQL report
Ahmad Zahid
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
Hammad Rasheed
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
Join in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer JoinJoin in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer Join
Souma Maiti
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Pooja Dixit
 
Joins in m ysql
Joins in m ysqlJoins in m ysql
Joins in m ysql
baabtra.com - No. 1 supplier of quality freshers
 
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptxLesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
quantumlearnai
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
sqljoins-220527115331-828e9932 (dee1).pptx
sqljoins-220527115331-828e9932 (dee1).pptxsqljoins-220527115331-828e9932 (dee1).pptx
sqljoins-220527115331-828e9932 (dee1).pptx
kailasmanoj
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ishucs
 
PRESENTATION........................pptx
PRESENTATION........................pptxPRESENTATION........................pptx
PRESENTATION........................pptx
ejazayesha485
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptx
KrishnansuSenapati
 
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjjKailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
Kailas Manoj SQL Joins.pptxhgvhhhbjgjjjjjgjgjjj
kailasmanoj
 
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbjKailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
Kailas Manoj SQL Joins.pdfhvhggjbhbbjbjbbjbj
kailasmanoj
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
Hammad Rasheed
 
Join in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer JoinJoin in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer Join
Souma Maiti
 
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptxLesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
quantumlearnai
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
sqljoins-220527115331-828e9932 (dee1).pptx
sqljoins-220527115331-828e9932 (dee1).pptxsqljoins-220527115331-828e9932 (dee1).pptx
sqljoins-220527115331-828e9932 (dee1).pptx
kailasmanoj
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ishucs
 
PRESENTATION........................pptx
PRESENTATION........................pptxPRESENTATION........................pptx
PRESENTATION........................pptx
ejazayesha485
 
Ad

More from Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
Mudasir Syed
 
Ajax
Ajax Ajax
Ajax
Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
Mudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
Mudasir Syed
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
Mudasir Syed
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
Mudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
Mudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
Mudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
Mudasir Syed
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
Mudasir Syed
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
Mudasir Syed
 
Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
Mudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
Mudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
Mudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
Mudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
Mudasir Syed
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
Mudasir Syed
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
Mudasir Syed
 

Recently uploaded (20)

GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 

PHP mysql Mysql joins

  • 2. MySQL Joins OverviewMySQL Joins Overview  MySQL Join is used to join the records from twoMySQL Join is used to join the records from two tables using join clause.tables using join clause.  The Join Clause return you the set of records fromThe Join Clause return you the set of records from both table on the basis of common column.both table on the basis of common column.
  • 3. MySQL Join TypesMySQL Join Types  MySQLMySQL Inner JoinInner Join  MySQL Equi JoinMySQL Equi Join  MySQL Natural JoinMySQL Natural Join  MySQL Cross JoinMySQL Cross Join  MySQL Outer JoinMySQL Outer Join  Left Outer JoinLeft Outer Join  Right Outer JoinRight Outer Join  Self JoinSelf Join
  • 4.  Inner joinInner join produces only the set of records that produces only the set of records that match in both Table A and Table B.match in both Table A and Table B. MySQL Inner JoinMySQL Inner Join
  • 5.  The INNER JOIN keyword returns rows when thereThe INNER JOIN keyword returns rows when there is at least one match in both tables.is at least one match in both tables.  If there are rows in "Persons" that do not haveIf there are rows in "Persons" that do not have matches in "Orders", those rows will NOT be listed.matches in "Orders", those rows will NOT be listed.  Example:Example:  SELECT Persons.LastName,SELECT Persons.LastName, Persons.FirstName, Orders.OrderNoPersons.FirstName, Orders.OrderNo FROM Persons INNER JOIN OrdersFROM Persons INNER JOIN Orders ON Persons.P_Id = Orders.P_IdON Persons.P_Id = Orders.P_Id ORDER BY Persons.LastNameORDER BY Persons.LastName (Contd:)MySQL Inner JoinMySQL Inner Join
  • 6. MySQL Outer JoinMySQL Outer Join  MySQL Outer Join return you the set of all matchingMySQL Outer Join return you the set of all matching records from both table.records from both table.  The Outer Join does not requires each records to beThe Outer Join does not requires each records to be matched in both the tables.matched in both the tables.  MySQL Outer Join is categorized into two groups.MySQL Outer Join is categorized into two groups.  MySQL Left Outer JoinMySQL Left Outer Join  MySQL Right Outer JoinMySQL Right Outer Join
  • 7. MySQL Left Outer JoinMySQL Left Outer Join  Left outer joinLeft outer join produces a complete set of records produces a complete set of records from Table A, with the matching records (wherefrom Table A, with the matching records (where available) in Table B. If there is no match, the right sideavailable) in Table B. If there is no match, the right side will contain null.will contain null.
  • 8. MySQL Left Outer JoinMySQL Left Outer Join  The left join is used in case of need to return all rowsThe left join is used in case of need to return all rows from the left table, even if the right table doesn't havefrom the left table, even if the right table doesn't have any match.any match.  Example:Example:  SELECT Persons.LastName,SELECT Persons.LastName, Persons.FirstName, Orders.OrderNoPersons.FirstName, Orders.OrderNo FROM Persons LEFT JOIN OrdersFROM Persons LEFT JOIN Orders ON Persons.P_Id=Orders.P_IdON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastNameORDER BY Persons.LastName (Contd:)
  • 9. MySQL Right Outer JoinMySQL Right Outer Join  The right join is used in case of need to return allThe right join is used in case of need to return all rows from the right table, even if the left tablerows from the right table, even if the left table doesn't have any match.doesn't have any match.  Example:Example:  SELECT Persons.LastName,Persons.FirstName,SELECT Persons.LastName,Persons.FirstName, Orders.OrderNoOrders.OrderNo FROM Persons RIGHT JOIN OrdersFROM Persons RIGHT JOIN Orders ON Persons.P_Id = Orders.P_IdON Persons.P_Id = Orders.P_Id ORDER BY Persons.LastNameORDER BY Persons.LastName
  • 10. MySQL Cross JoinMySQL Cross Join  Cross Join is also called Cartesian Product Join.Cross Join is also called Cartesian Product Join.  The Cross Join in SQL return you  a result table inThe Cross Join in SQL return you  a result table in which each row from the first table is combined withwhich each row from the first table is combined with each rows from the second table.each rows from the second table.
  • 11. MySQL Cross JoinMySQL Cross Join  In other words, you can say it is the crossIn other words, you can say it is the cross multiplication of number of rows in each table.multiplication of number of rows in each table.   Example:Example:  SELECT * FROM persons cross join orders;SELECT * FROM persons cross join orders; (Contd:)
  • 12. MySQL Equi JoinMySQL Equi Join  Equi Join is a classified type of Inner Join in Mysql.Equi Join is a classified type of Inner Join in Mysql.  Equi Join is used to combine records from two tableEqui Join is used to combine records from two table based on the common column exists in both table.based on the common column exists in both table.  The Equi Join returns you only those records whichThe Equi Join returns you only those records which are available in both table on the basis of commonare available in both table on the basis of common primary field name.primary field name.  Example:Example:  SELECT persons.firstname,orders.orderNoSELECT persons.firstname,orders.orderNo FROM persons, ordersFROM persons, orders WHERE persons.p_id = orders.p_id;WHERE persons.p_id = orders.p_id;
  • 13. MySQL Natural JoinMySQL Natural Join  MySQL Natural Join is a specialization of equi-joins.MySQL Natural Join is a specialization of equi-joins.  The join compares all columns in both tables thatThe join compares all columns in both tables that have the same column-name in both tables that havehave the same column-name in both tables that have column name in the joined table.column name in the joined table.  Example:Example:  SELECT persons.firstname, orders.orderNoSELECT persons.firstname, orders.orderNo FROM persons NATURAL JOIN orders;FROM persons NATURAL JOIN orders;
  • 14. MySQL Self JoinMySQL Self Join  These join allow you to retrieve related recordsThese join allow you to retrieve related records from the same table. from the same table.   The most common case where you'd use a self-join isThe most common case where you'd use a self-join is when you have a table that references itself.when you have a table that references itself.  Example:Example:  SELECT m.name as "Manager", p.name asSELECT m.name as "Manager", p.name as "Employee“"Employee“ FROM employee m, employee pFROM employee m, employee p WHERE m.emp_id = p.manager_id;WHERE m.emp_id = p.manager_id;