SlideShare a Scribd company logo
MySQL JOINS
What are JOINS?
 Joins help retrieving data from two or more database tables.
 The tables are mutually related using primary and foreign keys.
MySQL Cross Join
 Cross JOIN is a simplestform of JOINs which matches each row from one databasetable to all
rows of another.
 In other words it gives us combinations of each row of first table with all records in second table.
Cross Join
All rows from both tables
MySQL Cross Join
 All mentioned bellow lines will produce the same result:
SELECT * FROM table_1 CROSS JOIN table_2;
OR
SELECT table_1.id, table_1.greeting, table_2.id, table_2.question FROM table_1 CROSS JOIN table_2;
OR
SELECT table_1.id, table_1.greeting, table_2.id, table_2.question FROM table_1 , table_2;
MySQL Cross Join
id greeting
1 hello
2 hi
id question
1 How are you doing?
2 Are you there?
table_1 table_2
SELECT * FROM table_1 CROSS JOIN table_2;
Result
1
2
1
2
MySQL Inner Join
 The inner JOIN is used to return rows from both tables that satisfy the given condition.
 The inner JOIN is same as JOIN clause, combining rows from two or more tables.
Inner Join
Only matching rows
MySQL Inner Join
 Both lines will produce the same result:
SELECT * FROM table_1 INNER JOIN table_2 ON table_1.id = table_2.id;
OR
SELECT * FROM table_1 JOIN table_2 ON table_1.id = table_2.id;;
MySQL Inner Join
id greeting
1 hello
2 hi
id question
1 How are you doing?
2 Are you there?
table_1 table_2
SELECT * FROM table_1 INNER JOIN table_2 ON table_1.id = table_2.id;
Result
MySQL Outer Join
 MySQL does not support outer join.
MySQL Left Join
 The LEFT JOIN returns all the rows from the table on the left even if no matching rows
have been found in the table on the right.
 Where no matches have been found in the table on the right, NULL is returned
Left Join
All rows from the left table
MySQL Left Join
 Both lines will produce the same result:
SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.id = table_2.id;
OR
SELECT * FROM table_1 LEFT OUTER JOIN table_2 ON table_1.id = table_2.id;;
MySQL Left Join
id greeting
1 hello
2 hi
3 hey
id question
1 How are you doing?
2 Are you there?
table_1 table_2
SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.id = table_2.id;
Result
MySQL Right Join
 The RIGHT JOIN returns all the columns from the table on the right even if no matching
rows have been found in the table on the left.
 Where no matches have been found in the table on the left, NULL is returned.
Right Join
All rows from the right table
MySQL Right Join
 Both lines will produce the same result:
SELECT * FROM table_1 RIGHT JOIN table_2 ON table_1.id = table_2.id;
OR
SELECT * FROM table_1 RIGHT OUTER JOIN table_2 ON table_1.id = table_2.id;;
MySQL Right Join
id greeting
1 hello
2 hi
id question
1 How are you doing?
2 Are you there?
3 Are you ready?
table_1 table_2
SELECT * FROM table_1 RIGHT JOIN table_2 ON table_1.id = table_2.id;
Result
MySQL Right Join with USING clause
id question
1 How are you doing?
2 Are you there?
3 Are you ready?
table_1 table_2
SELECT * FROM table_1 RIGHT JOIN table_2 USING(id);
Result
id greeting
1 hello
2 hi
Why we use JOINs
 Using JOINs, you can get the work done by using only a one query with any search
parameters.
 MySQL can achieve better performance with JOINs as it can use Indexing. Simply use of single
JOIN query instead running multiple queries do reduce server overhead. Using multiple
queries instead that leads more data transfers between MySQL and applications (software).
Further it requires more data manipulations in application end also.
MySQL JOINS

More Related Content

What's hot

SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
zahid6
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
webhostingguy
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ishucs
 
Sql commands
Sql commandsSql commands
Mysql
MysqlMysql
Mysql
TSUBHASHRI
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
Nicole Ryan
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Sql joins
Sql joinsSql joins
Sql joins
Berkeley
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
I L0V3 CODING DR
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
Bwsrang Basumatary
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 

What's hot (20)

SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
Sql commands
Sql commandsSql commands
Sql commands
 
Mysql
MysqlMysql
Mysql
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql joins
Sql joinsSql joins
Sql joins
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 

Similar to MySQL JOINS

V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
Dhirendra Chauhan
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
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
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Pooja Dixit
 
Join query
Join queryJoin query
Join query
Waqar Ali
 
Joining
JoiningJoining
Joining
Abrar ali
 
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
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
johnwick814916
 
types of SQL Joins
 types of SQL Joins types of SQL Joins
types of SQL Joins
vikram rajpurohit
 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
ArunkumarT51
 
database .pptx
database .pptxdatabase .pptx
database .pptx
Mohammad Adnan
 
Sql server ___________session_11-12(joins)
Sql server  ___________session_11-12(joins)Sql server  ___________session_11-12(joins)
Sql server ___________session_11-12(joins)
Ehtisham Ali
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
Mudasir Syed
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
SangitaKabi
 
Sql joins
Sql joinsSql joins
Sql joins
LokeshGogia2
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
Joshi Vinay
 
Sql joins final
Sql joins finalSql joins final
Sql joins final
mbadhi
 
Using mySQL in PHP
Using mySQL in PHPUsing mySQL in PHP
Using mySQL in PHP
Mike Crabb
 

Similar to MySQL JOINS (20)

V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
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
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Join query
Join queryJoin query
Join query
 
Joining
JoiningJoining
Joining
 
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
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
 
types of SQL Joins
 types of SQL Joins types of SQL Joins
types of SQL Joins
 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
 
database .pptx
database .pptxdatabase .pptx
database .pptx
 
Sql server ___________session_11-12(joins)
Sql server  ___________session_11-12(joins)Sql server  ___________session_11-12(joins)
Sql server ___________session_11-12(joins)
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
 
Sql joins
Sql joinsSql joins
Sql joins
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Sql joins final
Sql joins finalSql joins final
Sql joins final
 
Using mySQL in PHP
Using mySQL in PHPUsing mySQL in PHP
Using mySQL in PHP
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 

MySQL JOINS

  • 2. What are JOINS?  Joins help retrieving data from two or more database tables.  The tables are mutually related using primary and foreign keys.
  • 3. MySQL Cross Join  Cross JOIN is a simplestform of JOINs which matches each row from one databasetable to all rows of another.  In other words it gives us combinations of each row of first table with all records in second table. Cross Join All rows from both tables
  • 4. MySQL Cross Join  All mentioned bellow lines will produce the same result: SELECT * FROM table_1 CROSS JOIN table_2; OR SELECT table_1.id, table_1.greeting, table_2.id, table_2.question FROM table_1 CROSS JOIN table_2; OR SELECT table_1.id, table_1.greeting, table_2.id, table_2.question FROM table_1 , table_2;
  • 5. MySQL Cross Join id greeting 1 hello 2 hi id question 1 How are you doing? 2 Are you there? table_1 table_2 SELECT * FROM table_1 CROSS JOIN table_2; Result 1 2 1 2
  • 6. MySQL Inner Join  The inner JOIN is used to return rows from both tables that satisfy the given condition.  The inner JOIN is same as JOIN clause, combining rows from two or more tables. Inner Join Only matching rows
  • 7. MySQL Inner Join  Both lines will produce the same result: SELECT * FROM table_1 INNER JOIN table_2 ON table_1.id = table_2.id; OR SELECT * FROM table_1 JOIN table_2 ON table_1.id = table_2.id;;
  • 8. MySQL Inner Join id greeting 1 hello 2 hi id question 1 How are you doing? 2 Are you there? table_1 table_2 SELECT * FROM table_1 INNER JOIN table_2 ON table_1.id = table_2.id; Result
  • 9. MySQL Outer Join  MySQL does not support outer join.
  • 10. MySQL Left Join  The LEFT JOIN returns all the rows from the table on the left even if no matching rows have been found in the table on the right.  Where no matches have been found in the table on the right, NULL is returned Left Join All rows from the left table
  • 11. MySQL Left Join  Both lines will produce the same result: SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.id = table_2.id; OR SELECT * FROM table_1 LEFT OUTER JOIN table_2 ON table_1.id = table_2.id;;
  • 12. MySQL Left Join id greeting 1 hello 2 hi 3 hey id question 1 How are you doing? 2 Are you there? table_1 table_2 SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.id = table_2.id; Result
  • 13. MySQL Right Join  The RIGHT JOIN returns all the columns from the table on the right even if no matching rows have been found in the table on the left.  Where no matches have been found in the table on the left, NULL is returned. Right Join All rows from the right table
  • 14. MySQL Right Join  Both lines will produce the same result: SELECT * FROM table_1 RIGHT JOIN table_2 ON table_1.id = table_2.id; OR SELECT * FROM table_1 RIGHT OUTER JOIN table_2 ON table_1.id = table_2.id;;
  • 15. MySQL Right Join id greeting 1 hello 2 hi id question 1 How are you doing? 2 Are you there? 3 Are you ready? table_1 table_2 SELECT * FROM table_1 RIGHT JOIN table_2 ON table_1.id = table_2.id; Result
  • 16. MySQL Right Join with USING clause id question 1 How are you doing? 2 Are you there? 3 Are you ready? table_1 table_2 SELECT * FROM table_1 RIGHT JOIN table_2 USING(id); Result id greeting 1 hello 2 hi
  • 17. Why we use JOINs  Using JOINs, you can get the work done by using only a one query with any search parameters.  MySQL can achieve better performance with JOINs as it can use Indexing. Simply use of single JOIN query instead running multiple queries do reduce server overhead. Using multiple queries instead that leads more data transfers between MySQL and applications (software). Further it requires more data manipulations in application end also.