SlideShare a Scribd company logo
1 of 22
Proven Database for
IIOT Applications
SQLite
Learn the Music of Database
SESSION #2
SQLite Constraints & JOINS
www.inforepos.com
Agenda
• Constraints
• JOINS
www.inforepos.com
SQLite Constraints
• CONSTRAINTS are an integrity which defines some conditions that restrict the column to
contain the true data while inserting or updating or deleting. We can use two types of
constraints, that is column level or table level constraint. The column level constraints can
be applied only on a specific column where as table level constraints can be applied to the
whole table.
Column constraints:
• NOT NULL
• PRIMARY KEY (COMPOSITE PRIMARY KEY)
• UNIQUE
• CHECK
• FOREIGN KEY (COMPOSITE FOREIGN KEY)
Constraint Action Clauses
• ON DELETE
• NO ACTION
• CASCADE
• RESTRICT
www.inforepos.com
SQLite Constraints explained through HR schema
www.inforepos.com
SQLite JOINS
• INNER JOIN
• INNER JOIN selects all rows from both participating tables to appear in the result if and only if both tables meet the
conditions specified in the ON clause.
• LEFT OUTER JOIN
• Left Join or Left Outer Join operation takes two relations, A and B, and returns the inner join of A and B along with the
unmatched rows of A. A is the first relation defined in the FROM clause and is hence the left relation. The left join
includes the unmatched rows of the left relation along with the matched columns in the result.
• CROSS JOIN
• When the two tables have no relation in any way, SELECT would produce a more fundamental kind of join , which is
called a cross join or Cartesian join. CROSS JOIN produces a result set which is the product of rows of two associated
tables when no WHERE clause is used with CROSS JOIN.
• NATURAL JOIN
• NATURAL JOIN is such a join that performs the same task as an INNER or LEFT JOIN, in which the ON or USING clause
refers to all columns that the tables to be joined have in common. A natural join joins two tables by their common
column names. Thus, using the natural join you can get the inner join without having to add the join condition.
www.inforepos.com
SQL JOINS in General
INNER JOIN
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN
www.inforepos.com
JOINS
SQLite INNER JOIN
• INNER JOIN
• There are three types of INNER JOINS:
• INNER JOIN, NATURAL INNER JOIN, and CROSS INNER JOIN. The INNER keyword can be omitted.
SELECT result
FROM table1
INNER JOIN table2
ON table1.keyfield1 = table2.keyfield2
[WHERE expr]
www.inforepos.com
JOINS
SQLite INNER JOIN
INNER JOIN
Doctors Table
doctor_id doctor_name degree
---------- -------------- ----------
210 Dr. John Linga MD
211 Dr. Peter Hall MBBS
212 Dr. Ke Gee MD
213 Dr. Pat Fay MD
Doctor Visits Table
doctor_id patient_name v_date
---------- ------------ ----------
210 Julia Nayer 2013-10-15
214 TJ Olson 2013-10-14
215 John Seo 2013-10-15
212 James Marlow 2013-10-16
212 Jason Mallin 2013-10-12
SELECT
doctors.doctor_id, doctors.doctor_name, visits.patient_name
FROM doctors
INNER JOIN visits
ON doctors.doctor_id = visits.doctor_id
WHERE doctors.degree = 'MD';
Output:
doctor_id doctor_name patient_name
---------- -------------- ------------
210 Dr. John Linga Julia Nayer
212 Dr. Ke Gee James Marlow
212 Dr. Ke Gee Jason Mallin
www.inforepos.com
JOINS
SQLite INNER JOIN
• INNER JOIN Explanation
SELECT a.doctor_id,a.doctor_name,b.spl_descrip
FROM doctors a
INNER JOIN speciality b
ON a.doctor_id=b.doctor_id;
www.inforepos.com
JOINS
SQLite INNER JOIN
• INNER JOIN Explanation
SELECT a.doctor_id,a.doctor_name,
b.spl_descrip,c.patient_name,c.vdate
FROM doctors a
INNER JOIN speciality b
ON a.doctor_id=b.doctor_id
INNER JOIN visits c
ON a.doctor_id=c.doctor_id;
www.inforepos.com
JOINS
SQLite INNER JOIN
• INNER JOIN Explanation
SELECT a.doctor_id,a.doctor_name,
b.spl_descrip,c.patient_name,c.vdate
FROM doctors a
INNER JOIN speciality b
ON a.doctor_id=b.doctor_id
INNER JOIN visits c
ON a.doctor_id=c.doctor_id
WHERE a.doctor_id=212 AND c.vdate='2013-10-16';
www.inforepos.com
JOINS
SQLite LEFT JOIN or LEFT OUTER JOIN
• LEFT OUTER JOIN
SELECT result
FROM table1
LEFT [OUTER] JOIN table2
ON table1.keyfield1 = table2.keyfield2
[WHERE expr]
www.inforepos.com
JOINS
SQLite LEFT JOIN or LEFT OUTER JOIN
Output:
doctor_id doctor_name patient_name v_date
---------- -------------- ------------ ----------
210 Dr. John Linga Julia Nayer 2013-10-15
211 Dr. Peter Hall
212 Dr. Ke Gee James Marlow 2013-10-16
212 Dr. Ke Gee Jason Mallin 2013-10-12
213 Dr. Pat Fay
To find which doctor attended which patient and the date for attend
SELECT a.doctor_id,a.doctor_name,
c.patient_name,c.vdate
FROM doctors a
LEFT JOIN visits c
ON a.doctor_id=c.doctor_id;
LEFT OUTER JOIN
Doctors Table
doctor_id doctor_name degree
---------- -------------- ----------
210 Dr. John Linga MD
211 Dr. Peter Hall MBBS
212 Dr. Ke Gee MD
213 Dr. Pat Fay MD
Doctor Visits Table
doctor_id patient_name v_date
---------- ------------ ----------
210 Julia Nayer 2013-10-15
214 TJ Olson 2013-10-14
215 John Seo 2013-10-15
212 James Marlow 2013-10-16
212 Jason Mallin 2013-10-12
www.inforepos.com
JOINS
SQLite LEFT JOIN or LEFT OUTER JOIN
www.inforepos.com
JOINS
SQLite LEFT JOIN or LEFT OUTER JOIN
• LEFT JOIN with USING
SELECT doctor_id,doctor_name,
patient_name,vdate
FROM doctors
LEFT JOIN visits
USING(doctor_id);
doctor_id doctor_name patient_name vdate
---------- -------------- ------------ ----------
210 Dr. John Linga Julia Nayer 2013-10-15
211 Dr. Peter Hall
212 Dr. Ke Gee James Marlow 2013-10-16
212 Dr. Ke Gee Jason Mallin 2013-10-12
213 Dr. Pat Fay
• NATURAL LEFT OUTER JOIN
SELECT doctor_id,doctor_name,
patient_name,vdate
FROM doctors
NATURAL LEFT OUTER JOIN visits;
doctor_id doctor_name patient_name vdate
---------- -------------- ------------ ----------
210 Dr. John Linga Julia Nayer 2013-10-15
211 Dr. Peter Hall
212 Dr. Ke Gee James Marlow 2013-10-16
212 Dr. Ke Gee Jason Mallin 2013-10-12
213 Dr. Pat Fay
www.inforepos.com
JOINS
SQLite CROSS JOIN
• CROSS JOIN
SELECT [ * | table1.col1,table1.col2,...,
table2.col1,table2.col2,...]
FROM table1
[CROSS JOIN ] table2
WHERE condition;
Table_A
id des1 des2
---------- ---------- --------
100 desc11 desc12
101 desc21 desc22
102 desc31 desc32
Table_B
id des3 des4
---------- ---------- --------
101 desc41 desc42
103 desc51 desc52
105 desc61 desc62
SELECT *
FROM Table_A
CROSS JOIN Table_B;
SELECT *
FROM Table_A
CROSS JOIN Table_B
WHERE Table_A.id=Table_B.id;
www.inforepos.com
JOINS
SQLite NATURAL JOIN
• NATURAL JOIN
SELECT * FROM table1 NATURAL JOIN table2;
SELECT * FROM Table_A NATURAL JOIN Table_B;
SELECT * FROM Table_A INNER JOIN Table_B ON table_a.id=table_b.id;
NATURAL JOIN with WHERE clause
SELECT doctor_id, doctor_name, degree, patient_name, v_date FROM doctors
NATURAL JOIN visits WHERE doctors.degree = "MD";
NATURAL JOIN using three tables
SELECT doctor_id, doctor_name, degree, spl_descrip, patient_name, v_date
FROM doctors NATURAL JOIN specialty NATURAL JOIN visits
WHERE doctors.degree = 'MD';
www.inforepos.com
JOINS
Based on ANSI SQL & SET Theory
THANK YOU
For All Queries : info@inforepos.com
Proven Database for
IIOT Applications
SQLite
Learn the Music of Database
IR SQLite Session #2

More Related Content

Similar to IR SQLite Session #2

45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview QuestionsBest SEO Tampa
 
ADVANCED SQL FUNCTONS (1).pptx
ADVANCED SQL FUNCTONS (1).pptxADVANCED SQL FUNCTONS (1).pptx
ADVANCED SQL FUNCTONS (1).pptxshaikanjum16
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Performance tuning
Performance tuningPerformance tuning
Performance tuningami111
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJoel Brewer
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselyEnkitec
 
SQL Joinning.Database
SQL Joinning.DatabaseSQL Joinning.Database
SQL Joinning.DatabaseUmme habiba
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraintsmadhav bansal
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
ppt on data tab in ms.excel
ppt on data tab in ms.excelppt on data tab in ms.excel
ppt on data tab in ms.excelMayank Aggarwal
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3MuhammadWaheed44
 

Similar to IR SQLite Session #2 (20)

45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
SQL
SQLSQL
SQL
 
ADVANCED SQL FUNCTONS (1).pptx
ADVANCED SQL FUNCTONS (1).pptxADVANCED SQL FUNCTONS (1).pptx
ADVANCED SQL FUNCTONS (1).pptx
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
 
SQL Joinning.Database
SQL Joinning.DatabaseSQL Joinning.Database
SQL Joinning.Database
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
IR SQLite Session #3
IR SQLite Session #3IR SQLite Session #3
IR SQLite Session #3
 
ppt on data tab in ms.excel
ppt on data tab in ms.excelppt on data tab in ms.excel
ppt on data tab in ms.excel
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3
 

Recently uploaded

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

IR SQLite Session #2

  • 1. Proven Database for IIOT Applications SQLite Learn the Music of Database
  • 4. www.inforepos.com SQLite Constraints • CONSTRAINTS are an integrity which defines some conditions that restrict the column to contain the true data while inserting or updating or deleting. We can use two types of constraints, that is column level or table level constraint. The column level constraints can be applied only on a specific column where as table level constraints can be applied to the whole table. Column constraints: • NOT NULL • PRIMARY KEY (COMPOSITE PRIMARY KEY) • UNIQUE • CHECK • FOREIGN KEY (COMPOSITE FOREIGN KEY) Constraint Action Clauses • ON DELETE • NO ACTION • CASCADE • RESTRICT
  • 6. www.inforepos.com SQLite JOINS • INNER JOIN • INNER JOIN selects all rows from both participating tables to appear in the result if and only if both tables meet the conditions specified in the ON clause. • LEFT OUTER JOIN • Left Join or Left Outer Join operation takes two relations, A and B, and returns the inner join of A and B along with the unmatched rows of A. A is the first relation defined in the FROM clause and is hence the left relation. The left join includes the unmatched rows of the left relation along with the matched columns in the result. • CROSS JOIN • When the two tables have no relation in any way, SELECT would produce a more fundamental kind of join , which is called a cross join or Cartesian join. CROSS JOIN produces a result set which is the product of rows of two associated tables when no WHERE clause is used with CROSS JOIN. • NATURAL JOIN • NATURAL JOIN is such a join that performs the same task as an INNER or LEFT JOIN, in which the ON or USING clause refers to all columns that the tables to be joined have in common. A natural join joins two tables by their common column names. Thus, using the natural join you can get the inner join without having to add the join condition.
  • 7. www.inforepos.com SQL JOINS in General INNER JOIN LEFT OUTER JOIN RIGHT OUTER JOIN FULL OUTER JOIN
  • 8. www.inforepos.com JOINS SQLite INNER JOIN • INNER JOIN • There are three types of INNER JOINS: • INNER JOIN, NATURAL INNER JOIN, and CROSS INNER JOIN. The INNER keyword can be omitted. SELECT result FROM table1 INNER JOIN table2 ON table1.keyfield1 = table2.keyfield2 [WHERE expr]
  • 9. www.inforepos.com JOINS SQLite INNER JOIN INNER JOIN Doctors Table doctor_id doctor_name degree ---------- -------------- ---------- 210 Dr. John Linga MD 211 Dr. Peter Hall MBBS 212 Dr. Ke Gee MD 213 Dr. Pat Fay MD Doctor Visits Table doctor_id patient_name v_date ---------- ------------ ---------- 210 Julia Nayer 2013-10-15 214 TJ Olson 2013-10-14 215 John Seo 2013-10-15 212 James Marlow 2013-10-16 212 Jason Mallin 2013-10-12 SELECT doctors.doctor_id, doctors.doctor_name, visits.patient_name FROM doctors INNER JOIN visits ON doctors.doctor_id = visits.doctor_id WHERE doctors.degree = 'MD'; Output: doctor_id doctor_name patient_name ---------- -------------- ------------ 210 Dr. John Linga Julia Nayer 212 Dr. Ke Gee James Marlow 212 Dr. Ke Gee Jason Mallin
  • 10. www.inforepos.com JOINS SQLite INNER JOIN • INNER JOIN Explanation SELECT a.doctor_id,a.doctor_name,b.spl_descrip FROM doctors a INNER JOIN speciality b ON a.doctor_id=b.doctor_id;
  • 11. www.inforepos.com JOINS SQLite INNER JOIN • INNER JOIN Explanation SELECT a.doctor_id,a.doctor_name, b.spl_descrip,c.patient_name,c.vdate FROM doctors a INNER JOIN speciality b ON a.doctor_id=b.doctor_id INNER JOIN visits c ON a.doctor_id=c.doctor_id;
  • 12. www.inforepos.com JOINS SQLite INNER JOIN • INNER JOIN Explanation SELECT a.doctor_id,a.doctor_name, b.spl_descrip,c.patient_name,c.vdate FROM doctors a INNER JOIN speciality b ON a.doctor_id=b.doctor_id INNER JOIN visits c ON a.doctor_id=c.doctor_id WHERE a.doctor_id=212 AND c.vdate='2013-10-16';
  • 13. www.inforepos.com JOINS SQLite LEFT JOIN or LEFT OUTER JOIN • LEFT OUTER JOIN SELECT result FROM table1 LEFT [OUTER] JOIN table2 ON table1.keyfield1 = table2.keyfield2 [WHERE expr]
  • 14. www.inforepos.com JOINS SQLite LEFT JOIN or LEFT OUTER JOIN Output: doctor_id doctor_name patient_name v_date ---------- -------------- ------------ ---------- 210 Dr. John Linga Julia Nayer 2013-10-15 211 Dr. Peter Hall 212 Dr. Ke Gee James Marlow 2013-10-16 212 Dr. Ke Gee Jason Mallin 2013-10-12 213 Dr. Pat Fay To find which doctor attended which patient and the date for attend SELECT a.doctor_id,a.doctor_name, c.patient_name,c.vdate FROM doctors a LEFT JOIN visits c ON a.doctor_id=c.doctor_id; LEFT OUTER JOIN Doctors Table doctor_id doctor_name degree ---------- -------------- ---------- 210 Dr. John Linga MD 211 Dr. Peter Hall MBBS 212 Dr. Ke Gee MD 213 Dr. Pat Fay MD Doctor Visits Table doctor_id patient_name v_date ---------- ------------ ---------- 210 Julia Nayer 2013-10-15 214 TJ Olson 2013-10-14 215 John Seo 2013-10-15 212 James Marlow 2013-10-16 212 Jason Mallin 2013-10-12
  • 16. www.inforepos.com JOINS SQLite LEFT JOIN or LEFT OUTER JOIN • LEFT JOIN with USING SELECT doctor_id,doctor_name, patient_name,vdate FROM doctors LEFT JOIN visits USING(doctor_id); doctor_id doctor_name patient_name vdate ---------- -------------- ------------ ---------- 210 Dr. John Linga Julia Nayer 2013-10-15 211 Dr. Peter Hall 212 Dr. Ke Gee James Marlow 2013-10-16 212 Dr. Ke Gee Jason Mallin 2013-10-12 213 Dr. Pat Fay • NATURAL LEFT OUTER JOIN SELECT doctor_id,doctor_name, patient_name,vdate FROM doctors NATURAL LEFT OUTER JOIN visits; doctor_id doctor_name patient_name vdate ---------- -------------- ------------ ---------- 210 Dr. John Linga Julia Nayer 2013-10-15 211 Dr. Peter Hall 212 Dr. Ke Gee James Marlow 2013-10-16 212 Dr. Ke Gee Jason Mallin 2013-10-12 213 Dr. Pat Fay
  • 17. www.inforepos.com JOINS SQLite CROSS JOIN • CROSS JOIN SELECT [ * | table1.col1,table1.col2,..., table2.col1,table2.col2,...] FROM table1 [CROSS JOIN ] table2 WHERE condition; Table_A id des1 des2 ---------- ---------- -------- 100 desc11 desc12 101 desc21 desc22 102 desc31 desc32 Table_B id des3 des4 ---------- ---------- -------- 101 desc41 desc42 103 desc51 desc52 105 desc61 desc62 SELECT * FROM Table_A CROSS JOIN Table_B; SELECT * FROM Table_A CROSS JOIN Table_B WHERE Table_A.id=Table_B.id;
  • 18. www.inforepos.com JOINS SQLite NATURAL JOIN • NATURAL JOIN SELECT * FROM table1 NATURAL JOIN table2; SELECT * FROM Table_A NATURAL JOIN Table_B; SELECT * FROM Table_A INNER JOIN Table_B ON table_a.id=table_b.id; NATURAL JOIN with WHERE clause SELECT doctor_id, doctor_name, degree, patient_name, v_date FROM doctors NATURAL JOIN visits WHERE doctors.degree = "MD"; NATURAL JOIN using three tables SELECT doctor_id, doctor_name, degree, spl_descrip, patient_name, v_date FROM doctors NATURAL JOIN specialty NATURAL JOIN visits WHERE doctors.degree = 'MD';
  • 20. THANK YOU For All Queries : info@inforepos.com
  • 21. Proven Database for IIOT Applications SQLite Learn the Music of Database