SlideShare a Scribd company logo
16th Meeting
Module 3 – JOIN
9:00PM – 10:30 PM – March 10th, 2019
Lai Trung Minh Duc | DucLTM@outlook.com
Microsoft Student Partners Vietnam | Analytics Vietnam Community
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 1
Agenda
• Sets Theory review
• Relational Database review
• JOIN Syntax
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 2
Hello World,
Lai Trung Minh Duc
Former External Economics student @ FTU
Former Solution Architect @ Savills Vietnam
Information Assurance student @ FPT
Tech-writer @ Duck’s Tech Zone
Solution Architect @ Pizitech LTD.
Tech-trainer @ Microsoft Student Partners Vietnam
Tech-love: ASPNET Core, Python, Angular, ReactJS, Docker, SQL
Interests: Data Visualization, Data Analytics, Finance, Marketing, HR
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 3
Knowledge Review – Sets Theory
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 4
Knowledge Review – Relational Database
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 5
Knowledge Review – Relational Database
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 6
JOIN in SQL
• INNER JOIN
• OUTER JOIN
• LEFT JOIN
• RIGHT JOIN
• FULL JOIN
• CROSS JOIN
• SELF JOIN
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 7
Knowledge Review – JOIN in SQL
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 8
Work with specified
columns (conditional)
JOIN… ON <condition1>
AND <condition2> OR
<condition3>
Join Syntax
• ANSI SQL-92
• Tables joined by JOIN operator in FROM Clause
• Preferred syntax
• ANSI SQL-89
• Tables joined by commas in FROM Clause
• Not recommended: Accidental Cartesian products!
SELECT ...
FROM Table1 JOIN Table2
ON <on_predicate>;
SELECT ...
FROM Table1, Table2
WHERE <where_predicate>;
Inner Joins
• Return only rows where a match is found in both input tables
• Match rows based on attributes supplied in predicate
• If join predicate operator is =, also known as equi-join
Employee SalesOrder
Set returned
by inner join
SELECT emp.FirstName, ord.Amount
FROM HR.Employee AS emp
[INNER] JOIN Sales.SalesOrder AS ord
ON emp.EmployeeID = ord.EmployeeID
Outer Joins
• Return all rows from one table and any matching
rows from second table
• One table’s rows are “preserved”
• Designated with LEFT, RIGHT, FULL keyword
• All rows from preserved table output to result set
• Matches from other table retrieved
• Additional rows added to results for non-
matched rows
• NULLs added in places where attributes do not match
• Example: Return all employees and for those
who have taken orders, return the order
amount. Employees without matching orders
will display NULL for order amount.
Employee SalesOrder
Set returned
by left outer
join
SELECT emp.FirstName, ord.Amount
FROM HR.Employee AS emp
LEFT [OUTER] JOIN Sales.SalesOrder AS ord
ON emp.EmployeeID = ord.EmployeeID;
Cross Joins
• Combine each row from first table with each
row from second table
• All possible combinations output
• Logical foundation for inner and outer joins
• Inner join starts with Cartesian product, adds filter
• Outer join takes Cartesian output, filtered, adds
back non-matching rows (with NULL placeholders)
• Due to Cartesian product output, not typically
a desired form of join
• Some useful exceptions:
• Table of numbers, generating data for testing
Employee
EmployeeID FirstName
1 Dan
2 Aisha
Product
ProductID Name
1 Widget
2 Gizmo
Result
FirstName Name
Dan Widget
Dan Gizmo
Aisha Widget
Aisha Gizmo
SELECT emp.FirstName, prd.Name
FROM HR.Employee AS emp
CROSS JOIN Production.Product AS prd;
Knowledge Sharing
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 13
Work with all
columns (non-
conditional)
Notes
• ER Diagram
Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 14

More Related Content

PPTX
Access 2013 Unit B
PPTX
Electronic spreadsheet software
PPT
Spreadsheet fundamentals
PPTX
Introduction to excel - application to statistics
PPT
16 making charts
PPT
spreadsheet program
PDF
Quick Checks Computer
PPTX
Spreadsheet terminology
Access 2013 Unit B
Electronic spreadsheet software
Spreadsheet fundamentals
Introduction to excel - application to statistics
16 making charts
spreadsheet program
Quick Checks Computer
Spreadsheet terminology

What's hot (20)

PPTX
Spreadsheet basics ppt
PDF
PDF
Spreadsheet Package
PPT
Intro To Spreadsheets Y34
PPT
Msexcel module 2007
PPT
14 formulas and functions
PPTX
Excel Tips and Tricks
PPTX
EXCEL PRIMER
PPT
Spreadhsheets 1
PDF
[PDF] Optimization Modeling with Spreadsheets
PPTX
Office technology
PPTX
Introduction to Basic Spreadsheets
PPTX
Spreadsheet Purposes
PPTX
Spreadsheet Concepts
PPT
What is a spreadsheet
PPTX
Data Analysis & Visualization using MS. Excel
PPTX
Ms Excel- Its uses & Functions.pptx
PPTX
Spreadsheet Introduction - R.D.Sivakumar
PPTX
statistics M.Ed 1st Sem
Spreadsheet basics ppt
Spreadsheet Package
Intro To Spreadsheets Y34
Msexcel module 2007
14 formulas and functions
Excel Tips and Tricks
EXCEL PRIMER
Spreadhsheets 1
[PDF] Optimization Modeling with Spreadsheets
Office technology
Introduction to Basic Spreadsheets
Spreadsheet Purposes
Spreadsheet Concepts
What is a spreadsheet
Data Analysis & Visualization using MS. Excel
Ms Excel- Its uses & Functions.pptx
Spreadsheet Introduction - R.D.Sivakumar
statistics M.Ed 1st Sem
Ad

Similar to 20190310 - SQL Course - JOIN (20)

PPTX
Querying_with_T-SQL_-_03 (1).pptx
PPTX
Querying_with_T-SQL_-_03.pptx
PDF
BI Knowledge Sharing Session 2
PPT
electronicspreadsheet.pptx.ppt
PPTX
Northern New England Tableau User Group - September 2024 Meeting
PDF
20180908 - 10th Meeting - Power BI Module 2
PPTX
advanced database management system by uni
PDF
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
PPTX
Basic Excel Course.pptx
PPTX
Operate spreadsheet application database administration .pptx
PDF
A excel analysis toolpack -best
PPT
Topics-Ch4Ch5.ppt
PPT
Topics-Ch4Ch5.ppt
PPTX
Ch01 CMPT110
PPTX
Roll No. 26, 31 to 39 (G4) Use of MS-Excel in CA Profession (wecompress.com)....
PPT
PPTX
Ch02 cmpt110
PDF
MODULE 1.pdf foundations of data science for final
PPTX
Elementary Data Analysis with MS Excel_Day-2
PDF
20180901 - 9th Meeting - Power BI Module 0-1
Querying_with_T-SQL_-_03 (1).pptx
Querying_with_T-SQL_-_03.pptx
BI Knowledge Sharing Session 2
electronicspreadsheet.pptx.ppt
Northern New England Tableau User Group - September 2024 Meeting
20180908 - 10th Meeting - Power BI Module 2
advanced database management system by uni
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
Basic Excel Course.pptx
Operate spreadsheet application database administration .pptx
A excel analysis toolpack -best
Topics-Ch4Ch5.ppt
Topics-Ch4Ch5.ppt
Ch01 CMPT110
Roll No. 26, 31 to 39 (G4) Use of MS-Excel in CA Profession (wecompress.com)....
Ch02 cmpt110
MODULE 1.pdf foundations of data science for final
Elementary Data Analysis with MS Excel_Day-2
20180901 - 9th Meeting - Power BI Module 0-1
Ad

More from Duc Lai Trung Minh (20)

PDF
HCMUT IMP Computer Science 20 - E-Government from the view of Privacy
PDF
Vietnam Global Azure Bootcamp 2019 - Security on Azure Kubernetes Services wi...
PDF
21st Meeting - Compare SQL Server and MySQL
PDF
20180922 - 11st meeting - Power BI Module 3 - Part 1
PPTX
20180826 - 8th Meeting - Power BI Orientation
PDF
7th meeting - Analysis Toolpak - Solver - Forecast Worksheet
PDF
Oracle DB 11g R2 Research (Installation, Users and Privileges, Audit Trail, E...
PPTX
20180707 - 2nd meeting - Group Orientation
PPTX
20180701 - 1st Meeting - Data Science Orientation
DOCX
In your opinion, how to avoid communication barriers. Write a short paragraph...
DOCX
Computer Forensics Report - FRS301 - FPT University
PPTX
[MSPVN - Azure Workshop] Day 2 - Azure Web App and WooCommerce for Online Shop
PPTX
[MSPVN - Azure Workshop] Day 1 - Azure Web App with WordPress deployment
PDF
Duc Lai Trung Minh - Resume - Summer 2017
PDF
[Marketing Arena 2017][First Round] Team SHARP
PPTX
[Privacy and IT Ethics Presentation] Chapter 3: The Forth Amendment and emer...
PPTX
[LSC Training] Tech Training Session
PPTX
[FTU Presentation][KTDN07] Brands
PPTX
[FTU Presentation][KTDN07] Shortcut Story
PPTX
[MSP Winter Hackathon 2015] Đo Thân App
HCMUT IMP Computer Science 20 - E-Government from the view of Privacy
Vietnam Global Azure Bootcamp 2019 - Security on Azure Kubernetes Services wi...
21st Meeting - Compare SQL Server and MySQL
20180922 - 11st meeting - Power BI Module 3 - Part 1
20180826 - 8th Meeting - Power BI Orientation
7th meeting - Analysis Toolpak - Solver - Forecast Worksheet
Oracle DB 11g R2 Research (Installation, Users and Privileges, Audit Trail, E...
20180707 - 2nd meeting - Group Orientation
20180701 - 1st Meeting - Data Science Orientation
In your opinion, how to avoid communication barriers. Write a short paragraph...
Computer Forensics Report - FRS301 - FPT University
[MSPVN - Azure Workshop] Day 2 - Azure Web App and WooCommerce for Online Shop
[MSPVN - Azure Workshop] Day 1 - Azure Web App with WordPress deployment
Duc Lai Trung Minh - Resume - Summer 2017
[Marketing Arena 2017][First Round] Team SHARP
[Privacy and IT Ethics Presentation] Chapter 3: The Forth Amendment and emer...
[LSC Training] Tech Training Session
[FTU Presentation][KTDN07] Brands
[FTU Presentation][KTDN07] Shortcut Story
[MSP Winter Hackathon 2015] Đo Thân App

Recently uploaded (20)

PPTX
Database Infoormation System (DBIS).pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Foundation of Data Science unit number two notes
PPT
Reliability_Chapter_ presentation 1221.5784
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
Introduction to machine learning and Linear Models
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPT
ISS -ESG Data flows What is ESG and HowHow
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PDF
Lecture1 pattern recognition............
PDF
Mega Projects Data Mega Projects Data
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPT
Quality review (1)_presentation of this 21
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Database Infoormation System (DBIS).pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Foundation of Data Science unit number two notes
Reliability_Chapter_ presentation 1221.5784
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Introduction to machine learning and Linear Models
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
ISS -ESG Data flows What is ESG and HowHow
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Lecture1 pattern recognition............
Mega Projects Data Mega Projects Data
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Quality review (1)_presentation of this 21
Business Ppt On Nestle.pptx huunnnhhgfvu
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Galatica Smart Energy Infrastructure Startup Pitch Deck
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf

20190310 - SQL Course - JOIN

  • 1. 16th Meeting Module 3 – JOIN 9:00PM – 10:30 PM – March 10th, 2019 Lai Trung Minh Duc | DucLTM@outlook.com Microsoft Student Partners Vietnam | Analytics Vietnam Community Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 1
  • 2. Agenda • Sets Theory review • Relational Database review • JOIN Syntax Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 2
  • 3. Hello World, Lai Trung Minh Duc Former External Economics student @ FTU Former Solution Architect @ Savills Vietnam Information Assurance student @ FPT Tech-writer @ Duck’s Tech Zone Solution Architect @ Pizitech LTD. Tech-trainer @ Microsoft Student Partners Vietnam Tech-love: ASPNET Core, Python, Angular, ReactJS, Docker, SQL Interests: Data Visualization, Data Analytics, Finance, Marketing, HR Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 3
  • 4. Knowledge Review – Sets Theory Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 4
  • 5. Knowledge Review – Relational Database Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 5
  • 6. Knowledge Review – Relational Database Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 6
  • 7. JOIN in SQL • INNER JOIN • OUTER JOIN • LEFT JOIN • RIGHT JOIN • FULL JOIN • CROSS JOIN • SELF JOIN Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 7
  • 8. Knowledge Review – JOIN in SQL Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 8 Work with specified columns (conditional) JOIN… ON <condition1> AND <condition2> OR <condition3>
  • 9. Join Syntax • ANSI SQL-92 • Tables joined by JOIN operator in FROM Clause • Preferred syntax • ANSI SQL-89 • Tables joined by commas in FROM Clause • Not recommended: Accidental Cartesian products! SELECT ... FROM Table1 JOIN Table2 ON <on_predicate>; SELECT ... FROM Table1, Table2 WHERE <where_predicate>;
  • 10. Inner Joins • Return only rows where a match is found in both input tables • Match rows based on attributes supplied in predicate • If join predicate operator is =, also known as equi-join Employee SalesOrder Set returned by inner join SELECT emp.FirstName, ord.Amount FROM HR.Employee AS emp [INNER] JOIN Sales.SalesOrder AS ord ON emp.EmployeeID = ord.EmployeeID
  • 11. Outer Joins • Return all rows from one table and any matching rows from second table • One table’s rows are “preserved” • Designated with LEFT, RIGHT, FULL keyword • All rows from preserved table output to result set • Matches from other table retrieved • Additional rows added to results for non- matched rows • NULLs added in places where attributes do not match • Example: Return all employees and for those who have taken orders, return the order amount. Employees without matching orders will display NULL for order amount. Employee SalesOrder Set returned by left outer join SELECT emp.FirstName, ord.Amount FROM HR.Employee AS emp LEFT [OUTER] JOIN Sales.SalesOrder AS ord ON emp.EmployeeID = ord.EmployeeID;
  • 12. Cross Joins • Combine each row from first table with each row from second table • All possible combinations output • Logical foundation for inner and outer joins • Inner join starts with Cartesian product, adds filter • Outer join takes Cartesian output, filtered, adds back non-matching rows (with NULL placeholders) • Due to Cartesian product output, not typically a desired form of join • Some useful exceptions: • Table of numbers, generating data for testing Employee EmployeeID FirstName 1 Dan 2 Aisha Product ProductID Name 1 Widget 2 Gizmo Result FirstName Name Dan Widget Dan Gizmo Aisha Widget Aisha Gizmo SELECT emp.FirstName, prd.Name FROM HR.Employee AS emp CROSS JOIN Production.Product AS prd;
  • 13. Knowledge Sharing Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 13 Work with all columns (non- conditional)
  • 14. Notes • ER Diagram Lai Trung Minh Duc | March 2019 | DucLTM@outlook.com 14