SlideShare a Scribd company logo
JOINS
BY: Hira Khalid
JOINS
It is used to combine
rows from two or
more tables, based
on a related column
between them.
SELECT * FROM order JOIN customer
ON order.depno=customer.depno;
QUERY
TYPES OF JOINS
(INNER)
JOIN
LEFT
(OUTER)
JOIN
RIGHT
(OUTER)
JOIN
FULL
(OUTER)
JOIN
INNER JOIN
The INNER JOIN keyword selects records
that have matching values in both tables.
SYNTAX
SELECT * FROM orders JOIN customer
ON orders.depno=customers.depno;
EXAMPLE:
OrderID CustomerID EmployeeID OrderDate ShipperID
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
CustomerI
D
Customer
Name
ContactNam
e
Address City PostalCod
e
Country
1 Alfreds
Futterkis
te
Maria
Anders
Obere Str.
57
Berli
n
12209 Germany
2 Ana
Trujillo
Empared
ados y
helados
Ana Trujillo Avda. de la
Constituci
ón 2222
Méxic
o D.F.
05021 Mexico
3 Antonio
Moreno
Antonio
Moreno
Mataderos
2312
Méxic
o D.F.
05023 Mexico
SELECT * FROM order
INNER JOIN customer ON
order.depno=customer.depno;
JOIN Three Tables:
SELECT Orders.OrderID, Customers.CustomerName,
Shippers.ShipperName
FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID =
Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID =
Shippers.ShipperID);
EXAMPLE:
LEFT JOIN
• The LEFT JOIN keyword
returns all records from
the left table (table1), and
the matched records from
the right table (table2).
The result is NULL from
the right side, if there is
no match.
SYNTAX
•SELECT column_name(s)
FROM table1
LEFT JOIN table2 ON table1.
column_name = table2.colum
n_name;
EXAMPLE:
OrderID CustomerID EmployeeID OrderDate ShipperID
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
CustomerI
D
Custome
rName
ContactN
ame
Address City PostalCod
e
Country
1 Alfreds
Futterki
ste
Maria
Anders
Obere Str.
57
Berlin 12209 Germany
2 Ana
Trujillo
Empare
dados y
helados
Ana
Trujillo
Avda. de
la
Constituci
ón 2222
México
D.F.
05021 Mexico
3 Antonio
Moreno
Taquerí
a
Antonio
Moreno
Matadero
s 2312
México
D.F.
05023 Mexico
SELECT * FROM customer LEFT JOIN
order
ON customer.customerID=order.customerID;
RIGHT JOIN
The RIGHT JOIN keyword returns all records from the right table
(table2), and the matched records from the left table (table1). The
result is NULL from the left side, when there is no match.
SYNTAX
•SELECT column_name(s)
FROM table1
RIGHT JOIN table2 ON table1.column_name = table2.column_name
OrderI
D
CustomerI
D
EmployeeI
D
OrderDate ShipperID
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
EmployeeID LastName FirstName BirthDate Photo
1 Davolio Nancy 12/8/1968 EmpID1.pic
2 Fuller Andrew 2/19/1952 EmpID2.pic
3 Leverling Janet 8/30/1963 EmpID3.pic
EXAMPLE:
SELECT * FROM order RIGHT JOIN
employee
ON
order.EmployeeID=employee.EmployeeID;
FULL OUTER JOIN
Return all records when there is a match
in either left (table1) or right (table2) table
records.
SYNTAX
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2 ON table1.col
umn_name = table2.column_name;
EXAMPLE:
Customer
ID
Customer
Name
ContactN
ame
Address City PostalCod
e
Country
1 Alfreds
Futterkist
e
Maria
Anders
Obere Str.
57
Berlin 12209 Germany
2 Ana
Trujillo
Empareda
dos y
helados
Ana
Trujillo
Avda. de
la
Constituci
ón 2222
México
D.F.
05021 Mexico
3 Antonio
Moreno
Taquería
Antonio
Moreno
Matadero
s 2312
México
D.F.
05023 Mexico
OrderID CustomerID EmployeeID OrderDate ShipperID
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
SELECT Customers.CustomerName,
Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID=Orders.CustomerI
D;
SELF JOIN
A self JOIN is
a regular join,
but the table
is joined with
itself.
SYNTAX
SELECT column_n
ame(s)
FROM table1 T1,
table1 T2
WHERE condition;
EXAMPLE:
SELECT a.EmpName Name,b.EmpName Name
FROM emp a
INNER JOIN emp b
ON a.ManagerID=b.EmpID
RESULT:
UNION Each SELECT
statement within
UNION must have
the same number of
columns
The columns must
also have similar
data types
The columns in
each SELECT
statement must
also be in the same
order
The operator is
used to combine
the result-set of
two or more
SELECT
statements.
QUERY:
To allow
duplicate
values, use
UNION
ALL:
The UNION
operator
selects only
distinct values
by default
SELECT column_n
ame(s) FROM table
1 UNION ALL
SELECT column_n
ame(s) FROM table
2;
EXAMPLE:
Custome
rID
Custome
rName
Contact
Name
Address City PostalCo
de
Country
1 Alfreds
Futterkis
te
Maria
Anders
Obere
Str. 57
Berlin 12209 Germany
2 Ana
Trujillo
Empared
ados y
helados
Ana
Trujillo
Avda. de
la
Constitu
ción 2222
México
D.F.
05021 Mexico
3 Antonio
Moreno
Taquería
Antonio
Moreno
Matader
os 2312
México
D.F.
05023 Mexico
SELECT country FROM custo
mer
UNION
SELECT country FROM shipp
er
ORDER BY country
RESULT:
GROUP BY
The statement is often used
with aggregate functions
(COUNT, MAX, MIN, SUM,
AVG) to group the result-set by
one or more columns.
SYNTAX:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
EXAMPLE:
CustomerI
D
Customer
Name
ContactNa
me
Address City PostalCod
e
Country
1 Alfreds
Futterkist
e
Maria
Anders
Obere Str.
57
Berlin 12209 Germany
2 Ana
Trujillo
Empareda
dos y
helados
Ana
Trujillo
Avda. de la
Constituci
ón 2222
México
D.F.
05021 Mexico
3 Antonio
Moreno
Taquería
Antonio
Moreno
Mataderos
2312
México
D.F.
05023 Mexico
SELECT COUNT(Custo
merID), Country
FROM Customers
GROUP BY Country;
RESULT: SELECT COUNT(City)
FROM customer
GROUP BY City
HAVING
The HAVING clause was added to SQL because the
WHERE keyword could not be used with aggregate
functions.
SYNTAX:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
EXAMPLE:
SELECT
COUNT(CustomerID),Country
FROM customer
GROUP BY (CustomerID)
HAVING (CustomerID)<>3
Customer
ID
Customer
Name
ContactN
ame
Address City PostalCod
e
Country
1 Alfreds
Futterkist
e
Maria
Anders
Obere Str.
57
Berlin 12209 Germany
2 Ana
Trujillo
Empareda
dos y
helados
Ana
Trujillo
Avda. de
la
Constituci
ón 2222
México
D.F.
05021 Mexico
3 Antonio
Moreno
Taquería
Antonio
Moreno
Mataderos
2312
México
D.F.
05023 Mexico
RESULT:
Joins
Joins

More Related Content

Recently uploaded

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
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
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
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
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
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
 
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
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
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
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
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
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
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
 

Recently uploaded (20)

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
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
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
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
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
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
 
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
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
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
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
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
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
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
 

Featured

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Joins

  • 2. JOINS It is used to combine rows from two or more tables, based on a related column between them. SELECT * FROM order JOIN customer ON order.depno=customer.depno; QUERY
  • 4. INNER JOIN The INNER JOIN keyword selects records that have matching values in both tables. SYNTAX SELECT * FROM orders JOIN customer ON orders.depno=customers.depno;
  • 5. EXAMPLE: OrderID CustomerID EmployeeID OrderDate ShipperID 10308 2 7 1996-09-18 3 10309 37 3 1996-09-19 1 10310 77 8 1996-09-20 2 CustomerI D Customer Name ContactNam e Address City PostalCod e Country 1 Alfreds Futterkis te Maria Anders Obere Str. 57 Berli n 12209 Germany 2 Ana Trujillo Empared ados y helados Ana Trujillo Avda. de la Constituci ón 2222 Méxic o D.F. 05021 Mexico 3 Antonio Moreno Antonio Moreno Mataderos 2312 Méxic o D.F. 05023 Mexico SELECT * FROM order INNER JOIN customer ON order.depno=customer.depno;
  • 6. JOIN Three Tables: SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName FROM ((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID); EXAMPLE:
  • 7. LEFT JOIN • The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match. SYNTAX •SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1. column_name = table2.colum n_name;
  • 8. EXAMPLE: OrderID CustomerID EmployeeID OrderDate ShipperID 10308 2 7 1996-09-18 3 10309 37 3 1996-09-19 1 10310 77 8 1996-09-20 2 CustomerI D Custome rName ContactN ame Address City PostalCod e Country 1 Alfreds Futterki ste Maria Anders Obere Str. 57 Berlin 12209 Germany 2 Ana Trujillo Empare dados y helados Ana Trujillo Avda. de la Constituci ón 2222 México D.F. 05021 Mexico 3 Antonio Moreno Taquerí a Antonio Moreno Matadero s 2312 México D.F. 05023 Mexico SELECT * FROM customer LEFT JOIN order ON customer.customerID=order.customerID;
  • 9. RIGHT JOIN The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match. SYNTAX •SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name
  • 10. OrderI D CustomerI D EmployeeI D OrderDate ShipperID 10308 2 7 1996-09-18 3 10309 37 3 1996-09-19 1 10310 77 8 1996-09-20 2 EmployeeID LastName FirstName BirthDate Photo 1 Davolio Nancy 12/8/1968 EmpID1.pic 2 Fuller Andrew 2/19/1952 EmpID2.pic 3 Leverling Janet 8/30/1963 EmpID3.pic EXAMPLE: SELECT * FROM order RIGHT JOIN employee ON order.EmployeeID=employee.EmployeeID;
  • 11. FULL OUTER JOIN Return all records when there is a match in either left (table1) or right (table2) table records. SYNTAX SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.col umn_name = table2.column_name;
  • 12. EXAMPLE: Customer ID Customer Name ContactN ame Address City PostalCod e Country 1 Alfreds Futterkist e Maria Anders Obere Str. 57 Berlin 12209 Germany 2 Ana Trujillo Empareda dos y helados Ana Trujillo Avda. de la Constituci ón 2222 México D.F. 05021 Mexico 3 Antonio Moreno Taquería Antonio Moreno Matadero s 2312 México D.F. 05023 Mexico OrderID CustomerID EmployeeID OrderDate ShipperID 10308 2 7 1996-09-18 3 10309 37 3 1996-09-19 1 10310 77 8 1996-09-20 2 SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerI D;
  • 13. SELF JOIN A self JOIN is a regular join, but the table is joined with itself. SYNTAX SELECT column_n ame(s) FROM table1 T1, table1 T2 WHERE condition;
  • 14. EXAMPLE: SELECT a.EmpName Name,b.EmpName Name FROM emp a INNER JOIN emp b ON a.ManagerID=b.EmpID RESULT:
  • 15. UNION Each SELECT statement within UNION must have the same number of columns The columns must also have similar data types The columns in each SELECT statement must also be in the same order The operator is used to combine the result-set of two or more SELECT statements.
  • 16. QUERY: To allow duplicate values, use UNION ALL: The UNION operator selects only distinct values by default SELECT column_n ame(s) FROM table 1 UNION ALL SELECT column_n ame(s) FROM table 2;
  • 17. EXAMPLE: Custome rID Custome rName Contact Name Address City PostalCo de Country 1 Alfreds Futterkis te Maria Anders Obere Str. 57 Berlin 12209 Germany 2 Ana Trujillo Empared ados y helados Ana Trujillo Avda. de la Constitu ción 2222 México D.F. 05021 Mexico 3 Antonio Moreno Taquería Antonio Moreno Matader os 2312 México D.F. 05023 Mexico SELECT country FROM custo mer UNION SELECT country FROM shipp er ORDER BY country RESULT:
  • 18. GROUP BY The statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns. SYNTAX: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);
  • 19. EXAMPLE: CustomerI D Customer Name ContactNa me Address City PostalCod e Country 1 Alfreds Futterkist e Maria Anders Obere Str. 57 Berlin 12209 Germany 2 Ana Trujillo Empareda dos y helados Ana Trujillo Avda. de la Constituci ón 2222 México D.F. 05021 Mexico 3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico SELECT COUNT(Custo merID), Country FROM Customers GROUP BY Country; RESULT: SELECT COUNT(City) FROM customer GROUP BY City
  • 20. HAVING The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. SYNTAX: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);
  • 21. EXAMPLE: SELECT COUNT(CustomerID),Country FROM customer GROUP BY (CustomerID) HAVING (CustomerID)<>3 Customer ID Customer Name ContactN ame Address City PostalCod e Country 1 Alfreds Futterkist e Maria Anders Obere Str. 57 Berlin 12209 Germany 2 Ana Trujillo Empareda dos y helados Ana Trujillo Avda. de la Constituci ón 2222 México D.F. 05021 Mexico 3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico RESULT: