SlideShare a Scribd company logo
JOINS
NABAGESERA NULU
MBADHI BARNABAS
definitions
A JOIN is a means for combining fields from two tables by
using values common to each
• SQL joins are used to combine rows from two or more
tables.
OR
• An SQL JOIN clause is used to combine rows from two or
more tables, based on a common field between them.
Type of SQL JOINs
• INNER JOIN: Returns all rows when there is at least one match in
BOTH tables
• LEFT JOIN: Return all rows from the left table, and the matched
rows from the right table
• RIGHT JOIN: Return all rows from the right table, and the matched
rows from the left table
• FULL JOIN: Return all rows when there is a match in ONE of the
tables
• SELF JOIN: Returns table to itself as if the table were two tables;
temporarily renaming at least one table in the SQL statement.
• CARTESIAN JOIN: Returns the Cartesian product of the sets of
records from two or more joined tables
SQL INNER JOIN
• The INNER JOIN keyword selects all rows from
both tables as long as there is a match between
the columns in both tables.
• SQL INNER JOIN Syntax
• SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
• Lets look at the tables on the preceding slides
SQL INNER JOIN
OrderID CustomerID OrderDate
101 1 2019-03-18
102 2 2019-03-19
103 3 2019-03-20
104 null 2019-03-21
CustomerID CustomerName ContactName district
1 Olumonde Godie wakiso
2 Gamukama Raymond luwero
3 Nabacwa Milica kampala
4 Kahinda Adon null
Customers table:
orders table:
SQL INNER JOIN
The relationship between the two tables above is the "CustomerID"
column.
• Then, if we run the following SQL statement (that contains an INNER
JOIN):
Example
SELECT
Customers.CustomerID,
Customers.CustomerName,
Customers.ContactName,
Customers.district,
Orders.OrderID,
Orders.OrderDate
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;
SQL INNER JOIN
• Output would be
CustomerID CustomerName ContactName district OrderID OrderDate
1 Olumonde Godie wakiso 101 2019-03-18
2 Gamukama Raymond luwero 102 2019-03-19
3 Nabacwa Milica kampala 103 2019-03-20
Note: (It selects all rows from both tables as long
as there is a match between the columns in both
tables)
.
SQL LEFT JOIN Keyword
• The LEFT JOIN keyword returns all rows from the left
table (table1), with the matching rows in the right table
(table2). The result is NULL in the right side when there
is no match.
SQL LEFT JOIN Syntax
• SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;
• In some databases LEFT OUTER JOIN is called LEFT
JOIN.
Using our tables above,
The following SQL statement will return all customers, and
any orders they might have:
SELECT
Customers.CustomerID,
Customers.CustomerName,
Customers.ContactName,
Customers.district,
Orders.OrderID,
Orders.OrderDate
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;
SQL LEFT JOIN Example
Note: The LEFT JOIN keyword returns all the rows from the left table
(Customers), even if there are no matches in the right table (Orders).
CustomerID CustomerName ContactName district OrderID OrderDate
1 Olumonde Godie wakiso 101 3/18/2019
2 Gamukama Raymond luwero 102 3/19/2019
3 Nabacwa Milica kampala 103 3/20/2019
4 Kahinda Adon null null null
SQL RIGHT JOIN Keyword
• The RIGHT JOIN keyword returns all rows from the
right table (table2), with the matching rows in the left
table (table1). The result is NULL in the left side when
there is no match.
• SQL RIGHT JOIN Syntax
SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;
NB:In some databases RIGHT OUTER JOIN is called
RIGHT JOIN.
Using our tables above,
The following SQL statement will return all employees, and
any orders they have placed:
SELECT
Customers.CustomerID,
Customers.CustomerName,
Customers.ContactName,
Customers.district,
Orders.OrderID,
Orders.OrderDate
FROM Customers
RIGHT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;
SQL RIGHT JOIN Example
• Note: The RIGHT JOIN keyword returns all the rows from the right table
(Employees), even if there are no matches in the left table (Orders).
CustomerID CustomerName ContactName district OrderID OrderDate
1 Olumonde Godie wakiso 101 3/18/2019
2 Gamukama Raymond luwero 102 3/19/2019
3 Nabacwa Milica kampala 103 3/20/2019
null null null null 104 3/21/2019
SQL FULL OUTER JOIN Keyword
• The FULL OUTER JOIN keyword returns all rows
from the left table (table1) and from the right table
(table2).
• To achieve that, we use the join keyword
• The JOIN keyword combines the result of both LEFT
and RIGHT joins.
SQL FULL OUTER JOIN Syntax
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;
SQL FULL OUTER JOIN Example
• Using our tables above,
• The following SQL statement selects all customers, and all orders:
SELECT
Customers.CustomerID,
Customers.CustomerName,
Customers.ContactName,
Customers.district,
Orders.OrderID,
Orders.OrderDate
FROM Customers
RIGHT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;
Note: The JOIN keyword returns all the rows from the left table (Customers), and all the rows from the
right table (Orders). If there are rows in "Customers" that do not have matches in "Orders", or if there are
rows in "Orders" that do not have matches in "Customers", those rows will be listed as well.
CustomerID CustomerName ContactName district OrderID OrderDate
1 Olumonde Godie wakiso 101 3/18/2019
2 Gamukama Raymond luwero 102 3/19/2019
3 Nabacwa Milica kampala 103 3/20/2019
4 Kahinda Adon null null null
null null null null 104 3/21/2019
SELF JOIN
• is used to join a table to itself as if the table were two
tables; temporarily renaming at least one table in the SQL
statement.
SELECT a.column_name, b.column_name...
FROM table1 a, table1 b
WHERE a.common_field = b.common_field;
Here, the WHERE clause could be any given expression
based on your requirement, for example.(a.value>b.value)
CARTESIAN JOIN
• it returns the Cartesian product of the sets of records from
two or more joined tables. Thus, it equates to an inner join
where the join-condition always evaluates to either True
or where the join-condition is absent from the statement.
SELECT table1.column1, table2.column2...
FROM table1, table2 ;
THANK YOU FOR ATTENDING

More Related Content

What's hot

Join query
Join queryJoin query
Join query
Waqar Ali
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Wings Interactive
 
SQL
SQLSQL
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
PuNeEt KuMaR
 
SQL Join's
SQL Join'sSQL Join's
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
DataminingTools Inc
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
Jamshid Hashimi
 
Excel 2013 Unit A
Excel 2013 Unit AExcel 2013 Unit A
Excel 2013 Unit A
jarana00
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
Ritwik Das
 
Sql joins
Sql joinsSql joins
Sql joins
Berkeley
 
Intro to Excel Basics: Part II
Intro to Excel Basics: Part IIIntro to Excel Basics: Part II
Intro to Excel Basics: Part II
Si Krishan
 
SQL Joinning.Database
SQL Joinning.DatabaseSQL Joinning.Database
SQL Joinning.Database
Umme habiba
 
Sql joins
Sql joinsSql joins
Sql joins
Ashok Kumar
 
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 Tutorial
SpreadsheetTrainer
 
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
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
DataminingTools Inc
 
Intermediate ms excel for business elective course for dlsu-d hs
Intermediate ms excel for business   elective course for dlsu-d hsIntermediate ms excel for business   elective course for dlsu-d hs
Intermediate ms excel for business elective course for dlsu-d hs
MarkFreudBolima
 
Excel 2013 Unit B
Excel 2013 Unit BExcel 2013 Unit B
Excel 2013 Unit B
jarana00
 
Intro to Excel Basics: Part I
Intro to Excel Basics: Part IIntro to Excel Basics: Part I
Intro to Excel Basics: Part I
Si Krishan
 

What's hot (20)

Join query
Join queryJoin query
Join query
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
SQL
SQLSQL
SQL
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
SQL Join's
SQL Join'sSQL Join's
SQL Join's
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
Excel 2013 Unit A
Excel 2013 Unit AExcel 2013 Unit A
Excel 2013 Unit A
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
Sql joins
Sql joinsSql joins
Sql joins
 
Intro to Excel Basics: Part II
Intro to Excel Basics: Part IIIntro to Excel Basics: Part II
Intro to Excel Basics: Part II
 
SQL Joinning.Database
SQL Joinning.DatabaseSQL Joinning.Database
SQL Joinning.Database
 
Sql joins
Sql joinsSql joins
Sql joins
 
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 Tutorial
 
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
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Intermediate ms excel for business elective course for dlsu-d hs
Intermediate ms excel for business   elective course for dlsu-d hsIntermediate ms excel for business   elective course for dlsu-d hs
Intermediate ms excel for business elective course for dlsu-d hs
 
Excel 2013 Unit B
Excel 2013 Unit BExcel 2013 Unit B
Excel 2013 Unit B
 
Intro to Excel Basics: Part I
Intro to Excel Basics: Part IIntro to Excel Basics: Part I
Intro to Excel Basics: Part I
 

Similar to Sql joins final

SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
johnwick814916
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
Mukesh Tekwani
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
Ahmed Farag
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Integrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdfIntegrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdf
Saikrishna492522
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
Priyabrat Kar
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
Abdullah Khosa
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
SangitaKabi
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
Brian Foote
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
Best SEO Tampa
 
Unions and joins in mysql
Unions and joins in mysqlUnions and joins in mysql
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
 
Unit_9.pptx
Unit_9.pptxUnit_9.pptx
Unit_9.pptx
BhagyasriPatel1
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
AnishurRehman1
 
Sql
SqlSql
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
Iblesoft
 

Similar to Sql joins final (20)

SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Integrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdfIntegrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdf
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
 
Joins and Views.pptx
Joins and Views.pptxJoins and Views.pptx
Joins and Views.pptx
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 
Unions and joins in mysql
Unions and joins in mysqlUnions and joins in mysql
Unions and joins in mysql
 
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
 
Unit_9.pptx
Unit_9.pptxUnit_9.pptx
Unit_9.pptx
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
 
Sql
SqlSql
Sql
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 

Recently uploaded

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 

Recently uploaded (20)

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 

Sql joins final

  • 2. definitions A JOIN is a means for combining fields from two tables by using values common to each • SQL joins are used to combine rows from two or more tables. OR • An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.
  • 3. Type of SQL JOINs • INNER JOIN: Returns all rows when there is at least one match in BOTH tables • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table • FULL JOIN: Return all rows when there is a match in ONE of the tables • SELF JOIN: Returns table to itself as if the table were two tables; temporarily renaming at least one table in the SQL statement. • CARTESIAN JOIN: Returns the Cartesian product of the sets of records from two or more joined tables
  • 4. SQL INNER JOIN • The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. • SQL INNER JOIN Syntax • SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; • Lets look at the tables on the preceding slides
  • 5. SQL INNER JOIN OrderID CustomerID OrderDate 101 1 2019-03-18 102 2 2019-03-19 103 3 2019-03-20 104 null 2019-03-21 CustomerID CustomerName ContactName district 1 Olumonde Godie wakiso 2 Gamukama Raymond luwero 3 Nabacwa Milica kampala 4 Kahinda Adon null Customers table: orders table:
  • 6. SQL INNER JOIN The relationship between the two tables above is the "CustomerID" column. • Then, if we run the following SQL statement (that contains an INNER JOIN): Example SELECT Customers.CustomerID, Customers.CustomerName, Customers.ContactName, Customers.district, Orders.OrderID, Orders.OrderDate FROM Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID;
  • 7. SQL INNER JOIN • Output would be CustomerID CustomerName ContactName district OrderID OrderDate 1 Olumonde Godie wakiso 101 2019-03-18 2 Gamukama Raymond luwero 102 2019-03-19 3 Nabacwa Milica kampala 103 2019-03-20 Note: (It selects all rows from both tables as long as there is a match between the columns in both tables) .
  • 8. SQL LEFT JOIN Keyword • The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. SQL LEFT JOIN Syntax • SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON table1.column_name=table2.column_name; • In some databases LEFT OUTER JOIN is called LEFT JOIN.
  • 9. Using our tables above, The following SQL statement will return all customers, and any orders they might have: SELECT Customers.CustomerID, Customers.CustomerName, Customers.ContactName, Customers.district, Orders.OrderID, Orders.OrderDate FROM Customers LEFT JOIN Orders ON Customers.CustomerID=Orders.CustomerID;
  • 10. SQL LEFT JOIN Example Note: The LEFT JOIN keyword returns all the rows from the left table (Customers), even if there are no matches in the right table (Orders). CustomerID CustomerName ContactName district OrderID OrderDate 1 Olumonde Godie wakiso 101 3/18/2019 2 Gamukama Raymond luwero 102 3/19/2019 3 Nabacwa Milica kampala 103 3/20/2019 4 Kahinda Adon null null null
  • 11. SQL RIGHT JOIN Keyword • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. • SQL RIGHT JOIN Syntax SELECT column_name(s) FROM table1 RIGHT OUTER JOIN table2 ON table1.column_name=table2.column_name; NB:In some databases RIGHT OUTER JOIN is called RIGHT JOIN.
  • 12. Using our tables above, The following SQL statement will return all employees, and any orders they have placed: SELECT Customers.CustomerID, Customers.CustomerName, Customers.ContactName, Customers.district, Orders.OrderID, Orders.OrderDate FROM Customers RIGHT JOIN Orders ON Customers.CustomerID=Orders.CustomerID;
  • 13. SQL RIGHT JOIN Example • Note: The RIGHT JOIN keyword returns all the rows from the right table (Employees), even if there are no matches in the left table (Orders). CustomerID CustomerName ContactName district OrderID OrderDate 1 Olumonde Godie wakiso 101 3/18/2019 2 Gamukama Raymond luwero 102 3/19/2019 3 Nabacwa Milica kampala 103 3/20/2019 null null null null 104 3/21/2019
  • 14. SQL FULL OUTER JOIN Keyword • The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2). • To achieve that, we use the join keyword • The JOIN keyword combines the result of both LEFT and RIGHT joins. SQL FULL OUTER JOIN Syntax SELECT column_name(s) FROM table1 JOIN table2 ON table1.column_name=table2.column_name;
  • 15. SQL FULL OUTER JOIN Example • Using our tables above, • The following SQL statement selects all customers, and all orders: SELECT Customers.CustomerID, Customers.CustomerName, Customers.ContactName, Customers.district, Orders.OrderID, Orders.OrderDate FROM Customers RIGHT JOIN Orders ON Customers.CustomerID=Orders.CustomerID;
  • 16. Note: The JOIN keyword returns all the rows from the left table (Customers), and all the rows from the right table (Orders). If there are rows in "Customers" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Customers", those rows will be listed as well. CustomerID CustomerName ContactName district OrderID OrderDate 1 Olumonde Godie wakiso 101 3/18/2019 2 Gamukama Raymond luwero 102 3/19/2019 3 Nabacwa Milica kampala 103 3/20/2019 4 Kahinda Adon null null null null null null null 104 3/21/2019
  • 17. SELF JOIN • is used to join a table to itself as if the table were two tables; temporarily renaming at least one table in the SQL statement. SELECT a.column_name, b.column_name... FROM table1 a, table1 b WHERE a.common_field = b.common_field; Here, the WHERE clause could be any given expression based on your requirement, for example.(a.value>b.value)
  • 18. CARTESIAN JOIN • it returns the Cartesian product of the sets of records from two or more joined tables. Thus, it equates to an inner join where the join-condition always evaluates to either True or where the join-condition is absent from the statement. SELECT table1.column1, table2.column2... FROM table1, table2 ;
  • 19. THANK YOU FOR ATTENDING