SlideShare a Scribd company logo
1 of 14
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;

More Related Content

What's hot (20)

SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
 
A simple presentation on Relational Algebra
A simple presentation on Relational AlgebraA simple presentation on Relational Algebra
A simple presentation on Relational Algebra
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
3 - Integrity Constraints.pdf
3 - Integrity Constraints.pdf3 - Integrity Constraints.pdf
3 - Integrity Constraints.pdf
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Regular expression in javascript
Regular expression in javascriptRegular expression in javascript
Regular expression in javascript
 
Oracle Advanced SQL
Oracle Advanced SQLOracle Advanced SQL
Oracle Advanced SQL
 
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
 
Les07 (using the set operators)
Les07 (using the set operators)Les07 (using the set operators)
Les07 (using the set operators)
 
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
 
Redis Persistence
Redis  PersistenceRedis  Persistence
Redis Persistence
 
SQL
SQLSQL
SQL
 

Viewers also liked

Database normalization
Database normalizationDatabase normalization
Database normalizationJignesh 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 MySQLZendCon
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda 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 calculusemailharmeet
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 

Viewers also liked (10)

MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
Mysql count
Mysql countMysql count
Mysql count
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
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
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍程序猿都该知道的MySQL秘籍
程序猿都该知道的MySQL秘籍
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 

Similar to PHP mysql Mysql joins

Similar to PHP mysql Mysql joins (20)

Sql join
Sql  joinSql  join
Sql join
 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
 
Join sql
Join sqlJoin sql
Join sql
 
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
 
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
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
 
Sql slid
Sql slidSql slid
Sql slid
 
Joins.ppt
Joins.pptJoins.ppt
Joins.ppt
 
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
 
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
 
SQL report
SQL reportSQL report
SQL report
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
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
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Joins in m ysql
Joins in m ysqlJoins in m ysql
Joins in m ysql
 
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
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
joins in database
 joins in database joins in database
joins in database
 
V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
 

More from 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 2Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir 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 PHPMyAdminMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir 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.1Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir 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
 

More from Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
 
Ajax
Ajax Ajax
Ajax
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
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
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

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;