SlideShare a Scribd company logo
1 of 8
SQL
Querying Multiple Tables
Now It’s Relational!
SELECT c.CD_NAME, p.PREF_NAME, c.IN_STOCK
FROM CD_INVENTORY c, PERFORMERS p
WHERE c.PREF_ID = p.PREF_ID
AND c.IN_STOCK < 15;
More than 2 Tables!
SELECT c.CD_NAME, p.PREF_NAME, t.TYPE_NAME
FROM CD_INVENTORY c, PERFORMERS p,
PREF_TYPE t
WHERE c.PREF_ID = p.PREF_ID
AND p.TYPE_ID = t.TYPE_ID
AND TYPE_NAME = ‘Popular’;
Another Way to Join
SELECT c.CD_NAME, p.PREF_NAME, c.IN_STOCK
FROM CD_INVENTORY JOIN PERFORMERS p ON
c.PREF_ID = p.PREF_ID
WHERE c.IN_STOCK < 15;
LEFT OUTER JOIN
● Used to return all the rows from the LEFT
table, even if they don’t match
SELECT i.TITLE, t.TYPE_NAME, i.STOCK
FROM CD_INFO i LEFT OUTER JOIN CD_TYPE i
ON i.TYPE_ID = t.TYPE_ID;
RIGHT OUTER JOIN
Used to return all the rows from the RIGHT
table, even if they don’t match
SELECT i.TITLE, t.TYPE_NAME, i.STOCK
FROM CD_INFO i RIGHT OUTER JOIN CD_TYPE i
ON i.TYPE_ID = t.TYPE_ID;
FULL OUTER JOIN
Used to return all the UNMATCHED rows from
both tables
SELECT i.TITLE, t.TYPE_NAME, i.STOCK
FROM CD_INFO i FULL OUTER JOIN CD_TYPE i
ON i.TYPE_ID = t.TYPE_ID;
Combine Query Results
SELECT *
FROM CDS_CONTINUED
UNION
SELECT *
FROM CDS_DISCONTINUED;
● Must have same columns and data types!

More Related Content

Viewers also liked

PDB Provisioning with Oracle Multitenant Self Service Application
PDB Provisioning with Oracle Multitenant Self Service ApplicationPDB Provisioning with Oracle Multitenant Self Service Application
PDB Provisioning with Oracle Multitenant Self Service ApplicationLeighton Nelson
 
A Second Look at Oracle RAC 12c
A Second Look at Oracle RAC 12cA Second Look at Oracle RAC 12c
A Second Look at Oracle RAC 12cLeighton Nelson
 
Dbms Lec Uog 02
Dbms Lec Uog 02Dbms Lec Uog 02
Dbms Lec Uog 02smelltulip
 
Importance of data model
Importance of data modelImportance of data model
Importance of data modelyhen06
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPTTrinath
 
Signal encoding techniques
Signal encoding techniquesSignal encoding techniques
Signal encoding techniquesSyed Zaid Irshad
 

Viewers also liked (15)

Surya
SuryaSurya
Surya
 
Bn1030 oracle dba
Bn1030 oracle dbaBn1030 oracle dba
Bn1030 oracle dba
 
PDB Provisioning with Oracle Multitenant Self Service Application
PDB Provisioning with Oracle Multitenant Self Service ApplicationPDB Provisioning with Oracle Multitenant Self Service Application
PDB Provisioning with Oracle Multitenant Self Service Application
 
A Second Look at Oracle RAC 12c
A Second Look at Oracle RAC 12cA Second Look at Oracle RAC 12c
A Second Look at Oracle RAC 12c
 
Dbms Lec Uog 02
Dbms Lec Uog 02Dbms Lec Uog 02
Dbms Lec Uog 02
 
Importance of data model
Importance of data modelImportance of data model
Importance of data model
 
OLTP vs OLAP
OLTP vs OLAPOLTP vs OLAP
OLTP vs OLAP
 
OLAP
OLAPOLAP
OLAP
 
RDBMS.ppt
RDBMS.pptRDBMS.ppt
RDBMS.ppt
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Oltp vs olap
Oltp vs olapOltp vs olap
Oltp vs olap
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
 
Dbms models
Dbms modelsDbms models
Dbms models
 
Data model
Data modelData model
Data model
 
Signal encoding techniques
Signal encoding techniquesSignal encoding techniques
Signal encoding techniques
 

More from RJ Podeschi

The4PsDesigningMarketingCoursewithDisney_8-18-16
The4PsDesigningMarketingCoursewithDisney_8-18-16The4PsDesigningMarketingCoursewithDisney_8-18-16
The4PsDesigningMarketingCoursewithDisney_8-18-16RJ Podeschi
 
Millikin I.S. Nerd Night 3-30-2016
Millikin I.S. Nerd Night 3-30-2016Millikin I.S. Nerd Night 3-30-2016
Millikin I.S. Nerd Night 3-30-2016RJ Podeschi
 
Homecoming 2015 I.S. Announcements
Homecoming 2015 I.S. AnnouncementsHomecoming 2015 I.S. Announcements
Homecoming 2015 I.S. AnnouncementsRJ Podeschi
 
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...RJ Podeschi
 
SQL: The Language of Databases
SQL: The Language of DatabasesSQL: The Language of Databases
SQL: The Language of DatabasesRJ Podeschi
 
SQL: Creating and Altering Tables
SQL: Creating and Altering TablesSQL: Creating and Altering Tables
SQL: Creating and Altering TablesRJ Podeschi
 
SQL: Using Predicates
SQL: Using PredicatesSQL: Using Predicates
SQL: Using PredicatesRJ Podeschi
 

More from RJ Podeschi (7)

The4PsDesigningMarketingCoursewithDisney_8-18-16
The4PsDesigningMarketingCoursewithDisney_8-18-16The4PsDesigningMarketingCoursewithDisney_8-18-16
The4PsDesigningMarketingCoursewithDisney_8-18-16
 
Millikin I.S. Nerd Night 3-30-2016
Millikin I.S. Nerd Night 3-30-2016Millikin I.S. Nerd Night 3-30-2016
Millikin I.S. Nerd Night 3-30-2016
 
Homecoming 2015 I.S. Announcements
Homecoming 2015 I.S. AnnouncementsHomecoming 2015 I.S. Announcements
Homecoming 2015 I.S. Announcements
 
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...
Field Trip Learning: Measuring Effectiveness, Transfer, & Metacognition in th...
 
SQL: The Language of Databases
SQL: The Language of DatabasesSQL: The Language of Databases
SQL: The Language of Databases
 
SQL: Creating and Altering Tables
SQL: Creating and Altering TablesSQL: Creating and Altering Tables
SQL: Creating and Altering Tables
 
SQL: Using Predicates
SQL: Using PredicatesSQL: Using Predicates
SQL: Using Predicates
 

Recently uploaded

FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 

Recently uploaded (20)

FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 

SQL: Querying Multiple Tables

  • 2. Now It’s Relational! SELECT c.CD_NAME, p.PREF_NAME, c.IN_STOCK FROM CD_INVENTORY c, PERFORMERS p WHERE c.PREF_ID = p.PREF_ID AND c.IN_STOCK < 15;
  • 3. More than 2 Tables! SELECT c.CD_NAME, p.PREF_NAME, t.TYPE_NAME FROM CD_INVENTORY c, PERFORMERS p, PREF_TYPE t WHERE c.PREF_ID = p.PREF_ID AND p.TYPE_ID = t.TYPE_ID AND TYPE_NAME = ‘Popular’;
  • 4. Another Way to Join SELECT c.CD_NAME, p.PREF_NAME, c.IN_STOCK FROM CD_INVENTORY JOIN PERFORMERS p ON c.PREF_ID = p.PREF_ID WHERE c.IN_STOCK < 15;
  • 5. LEFT OUTER JOIN ● Used to return all the rows from the LEFT table, even if they don’t match SELECT i.TITLE, t.TYPE_NAME, i.STOCK FROM CD_INFO i LEFT OUTER JOIN CD_TYPE i ON i.TYPE_ID = t.TYPE_ID;
  • 6. RIGHT OUTER JOIN Used to return all the rows from the RIGHT table, even if they don’t match SELECT i.TITLE, t.TYPE_NAME, i.STOCK FROM CD_INFO i RIGHT OUTER JOIN CD_TYPE i ON i.TYPE_ID = t.TYPE_ID;
  • 7. FULL OUTER JOIN Used to return all the UNMATCHED rows from both tables SELECT i.TITLE, t.TYPE_NAME, i.STOCK FROM CD_INFO i FULL OUTER JOIN CD_TYPE i ON i.TYPE_ID = t.TYPE_ID;
  • 8. Combine Query Results SELECT * FROM CDS_CONTINUED UNION SELECT * FROM CDS_DISCONTINUED; ● Must have same columns and data types!