SlideShare una empresa de Scribd logo
1 de 38
What is SQL ?
SQL stands for Structured Query
Language.
SQL is a special-purpose programming
language designed for managing data held
in a relational database management
system (RDBMS).
SQL is used to communicate with a
database and lets you access and
manipulate databases.
SQL statements are
used to perform tasks
such as update data
on a database, or
retrieve data from a
database.
Some common
relational database
management systems
that use SQL are:
Oracle, Sybase,
Microsoft SQL Server,
and Access.
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
What can SQL do ?
What is a Relational Database
System ?
A relational database system contains one
or more objects called tables.
The data or information for the database
are stored in these tables.
Tables are uniquely identified by their
names and are comprised of columns and
rows.
Columns contain the column name, data
type, and any other attributes for the
column.
Rows contain the records or data for the
columns.
City High Low
Manila 101 92
Makati 88 69
Quezon City 77 60
Sample Table “Weather Temperature”
Columns
Rows
One of the most beneficial features of SQL
& relational database systems
Makes relational database systems
"relational".
Used to combine rows from two or more
tables, based on a common field between
them.
Allows you to link data from two or more
tables together into a single query result--
from one single SELECT statement.
What would happen if you worked with
one table only, and didn't have the
ability to use “JOIN". Let's say you have
a one-table database that is used to
keep track of all of your customers and
what they purchase from your store:
CID_No Surname First Address Date Item Price
Every time a new row is inserted into the
table, all columns will be updated, thus
resulting in unnecessary redundant data. For
example, every time Juan Tamad purchases
something, the following rows will be inserted
into the table:
CID_No. Surname First Address Date Item Price
10908 Tamad Juan 14 Sipag St., Manila 01/07/14 1K Rice 40.00
10908 Tamad Juan 14 Sipag St., Manila 01/08/14
Purefoods
Corned Beef
85.00
10908 Tamad Juan 14 Sipag St., Manila 01/09/14 555 Sardines 25.00
To eliminate unnecessary redundant data, our
database should have two tables :
1. One for keeping track of your customer
2. And the other to keep track of what they
purchase :
CID_No Surname First Address
CID_No Date Item Price
TABLE 1
Cust_Info Table
TABLE 2
Purchases Table
Now, whenever a purchase is made from a repeating
customer, the 2nd table, "Purchases" only needs to
be updated , eliminating useless redundant data.
Notice that both tables have a common “CID_No"
column.
CID_No Surname First Address
CID _No Date Item Price
TABLE 1
Cust_Info Table
TABLE 2
Purchases Table
Table 1
Cust_Info
Table 2
Purchases
CID_No
This column, which contains the unique customer
id number, will be used to JOIN the two tables.
The INNER JOIN keyword selects all rows from
both tables as long as there is a match between the
columns in both tables.
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
Notice that each of the columns are always
preceded with the table name and a period.
This is a good practice so that you wont
confuse which columns go with what tables.
It is also required if the name column names
are the same between the two tables.
SELECT cust_info.first, cust_info.surname,
purchases.item
FROM cust_info
INNER JOIN purchases
ON cust_info.cid_no = purchases.cid_no;
To JOIN the Cust_Info Table and the
Purchases Table using the CID_No
column that is found in both tables, we
have :
column_name(s)
table1
table 2
table1.column_name table2.column_name
If we execute these statements, using the data in
the tables below :
CID_No Surname First Address
10907 Clavio Arnold 7 Tahimik St, Quezon City
10908 Tamad Juan 14 Sipag St. Malate, Manila
10909 Santos Charo Laya Ave., Muntinlupa City
TABLE 1
Cust_Info Table
CID_No Date Item Price
10908 01/07/14 1K rice 40.00
10909 01/07/14 Papaya Soap 140.00
10907 01/07/14 1K Ampalaya 60.00
10908 01/08/14 Purefoods Corned Beef 85.00
10907 01/08/14 5K rice 350.00
10908 01/09/14 555 Sardines 25.00
TABLE 2
Purchases Table
We will have something like this :
First Surname Item
Arnold Clavio 1K Ampalaya
Arnold Clavio 5K rice
Juan Tamad 1K rice
Juan Tamad Purefoods Corned Beef
Juan Tamad 555 Sardines
Charo Santos Papaya Soap
TABLE ORDER :
STATEMENT 1 STATEMENT 2
SELECT * SELECT*
FROM Table1 FROM Table2
INNER JOIN Table2 INNER JOIN Table1
ON Table1.column_name ON Table2.column_name
*Table2.column_name *Table1.column_name
SPECIFIED COLUMNS :
SELECT specified_column/s
FROM Table1
INNER JOIN Table2
ON Table1.column_name = Table2.column_name
SELECT * FROM Table1,Table2
WHERE Table1.column_name = Table2.column_name
ALTERNATIVE :
INNER JOIN requires the existence of a match
between the tables based on specified column/s
and only matching records are selected.
The OUTER JOIN keyword does not require each
record in the two joined tables to have a matching
record. The joined table retains each record—
even if no other matching record exists.
LEFT JOIN - Returns all rows from the left
table for the first tables. Even if there are no
matches in the right.
Depending on which table’s rows are retained,
OUTER JOIN is subdivided into :
RIGHT JOIN - Return all the rows from the
right table ( or the second table) even if there
are no matches in the left table
FULL JOIN - Both tables are secondary (or
optional) such that if rows are being matched
in tabled A and table B then all rows from table
A are displayed even if there is no matching
row in table B and vice versa
Look at the tables below and note the
common column names between them :
EmployeeID EmpName
01-054 Jerry Mendoza
01-055 Dane Sevilla
01-056 Mylene Antonio
LogID EmployeeID LogDate
1 01-054 11-09-11
2 01-056 11-10-11
3 01-054 11-11-11
TimeRecID LogID TIn TOut
1 1 09:00 18:03
2 2 07:30 16:55
3 3 09:02 18:34
TABLE 1
Employee Table
TABLE 2
LogRecordsTable
TABLE 3
TimeRecordsTable
SELECT * FROM Employee AS e
LEFTJOIN LogRecords AS L
ON e.EmployeeID = L.EmployeeID
LEFT JOIN TimeRecords AS t
ON t.LogID = L.LogID
Employee
Table 1
e
LogRecords
Table 2
L
TimeRecords
Table 3
t
Employee
ID
EmpName LogID EmployeeID LogDate TimeRecID LogID TIn TOut
01-054
Jerry
Mendoza
1 01-054 11-09-11 1 1 09:00 18:03
01-054
Jerry
Mendoza
3 01-054 11-11-11 3 3 9:02 18:34
01-055
Dane
Sevilla
Null Null Null Null Null Null Null
01-056
Mylene
Antonio
2 01-056 11-10-11 2 2 7:30 16:55
NULL is returned where
no there are no matches
in the RIGHT table
SELECT e.EmpName, L.LogDate, t.Tin, t.Tout
FROM Employee AS e
LEFTJOIN LogRecords AS L
ON e.EmployeeID = L.EmployeeID
LEFT JOIN TimeRecords AS t
ON t.LogID = L.LogID
EmpName LogDate TIn TOut
Jerry Mendoza 11-09-11 09:00 18:03
Jerry Mendoza 11-11-11 9:02 18:34
Dane Sevilla Null Null Null
Mylene Antonio 11-10-11 7:30 16:55
SELECT e.EmpName, L.LogDate, t.Tin, t.Tout
FROM Employee AS e
LEFTJOIN LogRecords AS L
ON e.EmployeeID = L.EmployeeID
LEFT JOIN TimeRecords AS t
ON t.LogID = L.LogID
WHERE L.LogDate IS NOT NULL
EmpName LogDate TIn TOut
Jerry Mendoza 11-09-11 09:00 18:03
Jerry Mendoza 11-11-11 9:02 18:34
Mylene Antonio 11-10-11 7:30 16:55
SELECT e.EmpName, L.LogDate, t.Tin, t.Tout
FROM TimeRecords AS t
RIGHT JOIN LogRecords AS L
ON t.LogID = L.LogID
RIGHT JOIN Employee AS e
ON e.EmployeeID = L.EmployeeID
EmpName LogDate TIn TOut
Jerry Mendoza 11-09-11 09:00 18:03
Jerry Mendoza 11-11-11 9:02 18:34
Dane Sevilla Null Null Null
Mylene Antonio 11-10-11 7:30 16:55
In FULL JOIN, both tables are secondary (or
optional). In this case, if we are matching
rows in table A and B, then we display :
all rows from
table A even
if there is no
matching row
in table B
all rows from table B even if there is no
matching row in table A
TABLE A TABLE B
Look at the tables below and note the
common column names between them :
GenreCode GenreDesc
HR Horror
RC Romance
HS History
CY Comedy
SF Sci-Fi
MovieID MovieTitle GenreCode
1 Saw 4 HR
2 Bad Teacher CY
3 The Notebook RC
4 Shrek No code available
5 Schindler’s List HS
6 The Exorcist HR
TABLE 1
MovieList
TABLE 2
GenresTable
SELECT MovieTitle, GenreDesc
FROM MovieList AS m
FULLJOIN Genres AS g
ON m.GenreCode = g.GenreCode
MovieTitle GenreDesc
Saw 4 Horror
Bad Teacher Comedy
The Notebook Romance
Shrek NULL
Schindler’s List History
The Exorcist Horror
NULL Sci-Fi
JOIN’s are used to combine & get the data from
different tables.
INNER JOIN returns rows when there is a match
in both tables.
LEFT JOIN returns all rows from the left table,
even if there are no matches in the right table.
RIGHT JOIN returns all rows from the right
table, even if there are no matches in the left
table.
FULL JOIN returns rows when there is a match
in one of the tables.
NULL values are returned in the output
when no records are returned by an OUTER
JOIN statement
JOIN queries can be used with the
conjunction of SELECT
We can also use WHERE clauses along with
JOIN’s
Identify the type of JOIN shown in the
following diagrams :
Identify the following :
1. This is used to communicate with a
database and lets you access and
manipulate databases.
2. This is used to combine and get data from
different tables.
3. This returns rows when there is a match in
one of the tables.
4. This returns rows when there is a match in
both tables.
5. This returns all rows from the left table,
even if there are no matches in the right
table.
6. This is where one or more objects called
tables are contained.
7. This allows you to link data from two or
more tables together into a single query
result from one single SELECT statement
8. This returns all rows from the right table,
even if there are no matches in the left
table.
9. This is value returned in the output when
no records are returned by an OUTER
JOIN statement.
10. This conjunction can be used with JOIN
queries.
Inner join and outer join
Inner join and outer join

Más contenido relacionado

La actualidad más candente (20)

Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
joins in database
 joins in database joins in database
joins in database
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Join query
Join queryJoin query
Join query
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 

Similar a Inner join and outer join

Similar a Inner join and outer join (20)

SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
What is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdfWhat is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdf
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
 
Sql joins
Sql joinsSql joins
Sql joins
 
1 introduction to my sql
1 introduction to my sql1 introduction to my sql
1 introduction to my sql
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
 
Normalization
NormalizationNormalization
Normalization
 
Sql slid
Sql slidSql slid
Sql slid
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
MQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptxMQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptx
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
SQL report
SQL reportSQL report
SQL report
 
Join in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer JoinJoin in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer Join
 
4b6c1c5c-e913-4bbf-b3a4-41e23cb961ba-161004200047.pdf
4b6c1c5c-e913-4bbf-b3a4-41e23cb961ba-161004200047.pdf4b6c1c5c-e913-4bbf-b3a4-41e23cb961ba-161004200047.pdf
4b6c1c5c-e913-4bbf-b3a4-41e23cb961ba-161004200047.pdf
 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
 

Más de Nargis Ehsan

Más de Nargis Ehsan (11)

Huffman codes
Huffman codesHuffman codes
Huffman codes
 
Sqlite left outer_joins
Sqlite left outer_joinsSqlite left outer_joins
Sqlite left outer_joins
 
Sql5
Sql5Sql5
Sql5
 
Sql2
Sql2Sql2
Sql2
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1
 
Sql 3
Sql 3Sql 3
Sql 3
 
Quick sort algo analysis
Quick sort algo analysisQuick sort algo analysis
Quick sort algo analysis
 
Erd chapter 3
Erd chapter 3Erd chapter 3
Erd chapter 3
 
The relational database model chapter 2
The relational database model  chapter 2The relational database model  chapter 2
The relational database model chapter 2
 
Communication network
Communication networkCommunication network
Communication network
 
Communication network .ppt
Communication network  .pptCommunication network  .ppt
Communication network .ppt
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 

Inner join and outer join

  • 1.
  • 2. What is SQL ? SQL stands for Structured Query Language. SQL is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS). SQL is used to communicate with a database and lets you access and manipulate databases.
  • 3. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, and Access.
  • 4. SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database What can SQL do ?
  • 5. What is a Relational Database System ? A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows.
  • 6. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. City High Low Manila 101 92 Makati 88 69 Quezon City 77 60 Sample Table “Weather Temperature” Columns Rows
  • 7. One of the most beneficial features of SQL & relational database systems Makes relational database systems "relational". Used to combine rows from two or more tables, based on a common field between them. Allows you to link data from two or more tables together into a single query result-- from one single SELECT statement.
  • 8. What would happen if you worked with one table only, and didn't have the ability to use “JOIN". Let's say you have a one-table database that is used to keep track of all of your customers and what they purchase from your store: CID_No Surname First Address Date Item Price
  • 9. Every time a new row is inserted into the table, all columns will be updated, thus resulting in unnecessary redundant data. For example, every time Juan Tamad purchases something, the following rows will be inserted into the table: CID_No. Surname First Address Date Item Price 10908 Tamad Juan 14 Sipag St., Manila 01/07/14 1K Rice 40.00 10908 Tamad Juan 14 Sipag St., Manila 01/08/14 Purefoods Corned Beef 85.00 10908 Tamad Juan 14 Sipag St., Manila 01/09/14 555 Sardines 25.00
  • 10. To eliminate unnecessary redundant data, our database should have two tables : 1. One for keeping track of your customer 2. And the other to keep track of what they purchase : CID_No Surname First Address CID_No Date Item Price TABLE 1 Cust_Info Table TABLE 2 Purchases Table Now, whenever a purchase is made from a repeating customer, the 2nd table, "Purchases" only needs to be updated , eliminating useless redundant data.
  • 11. Notice that both tables have a common “CID_No" column. CID_No Surname First Address CID _No Date Item Price TABLE 1 Cust_Info Table TABLE 2 Purchases Table Table 1 Cust_Info Table 2 Purchases CID_No This column, which contains the unique customer id number, will be used to JOIN the two tables.
  • 12. The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; Notice that each of the columns are always preceded with the table name and a period. This is a good practice so that you wont confuse which columns go with what tables. It is also required if the name column names are the same between the two tables.
  • 13. SELECT cust_info.first, cust_info.surname, purchases.item FROM cust_info INNER JOIN purchases ON cust_info.cid_no = purchases.cid_no; To JOIN the Cust_Info Table and the Purchases Table using the CID_No column that is found in both tables, we have : column_name(s) table1 table 2 table1.column_name table2.column_name
  • 14. If we execute these statements, using the data in the tables below : CID_No Surname First Address 10907 Clavio Arnold 7 Tahimik St, Quezon City 10908 Tamad Juan 14 Sipag St. Malate, Manila 10909 Santos Charo Laya Ave., Muntinlupa City TABLE 1 Cust_Info Table CID_No Date Item Price 10908 01/07/14 1K rice 40.00 10909 01/07/14 Papaya Soap 140.00 10907 01/07/14 1K Ampalaya 60.00 10908 01/08/14 Purefoods Corned Beef 85.00 10907 01/08/14 5K rice 350.00 10908 01/09/14 555 Sardines 25.00 TABLE 2 Purchases Table
  • 15. We will have something like this : First Surname Item Arnold Clavio 1K Ampalaya Arnold Clavio 5K rice Juan Tamad 1K rice Juan Tamad Purefoods Corned Beef Juan Tamad 555 Sardines Charo Santos Papaya Soap
  • 16. TABLE ORDER : STATEMENT 1 STATEMENT 2 SELECT * SELECT* FROM Table1 FROM Table2 INNER JOIN Table2 INNER JOIN Table1 ON Table1.column_name ON Table2.column_name *Table2.column_name *Table1.column_name
  • 17. SPECIFIED COLUMNS : SELECT specified_column/s FROM Table1 INNER JOIN Table2 ON Table1.column_name = Table2.column_name SELECT * FROM Table1,Table2 WHERE Table1.column_name = Table2.column_name ALTERNATIVE :
  • 18. INNER JOIN requires the existence of a match between the tables based on specified column/s and only matching records are selected. The OUTER JOIN keyword does not require each record in the two joined tables to have a matching record. The joined table retains each record— even if no other matching record exists.
  • 19. LEFT JOIN - Returns all rows from the left table for the first tables. Even if there are no matches in the right. Depending on which table’s rows are retained, OUTER JOIN is subdivided into :
  • 20. RIGHT JOIN - Return all the rows from the right table ( or the second table) even if there are no matches in the left table
  • 21. FULL JOIN - Both tables are secondary (or optional) such that if rows are being matched in tabled A and table B then all rows from table A are displayed even if there is no matching row in table B and vice versa
  • 22. Look at the tables below and note the common column names between them : EmployeeID EmpName 01-054 Jerry Mendoza 01-055 Dane Sevilla 01-056 Mylene Antonio LogID EmployeeID LogDate 1 01-054 11-09-11 2 01-056 11-10-11 3 01-054 11-11-11 TimeRecID LogID TIn TOut 1 1 09:00 18:03 2 2 07:30 16:55 3 3 09:02 18:34 TABLE 1 Employee Table TABLE 2 LogRecordsTable TABLE 3 TimeRecordsTable
  • 23. SELECT * FROM Employee AS e LEFTJOIN LogRecords AS L ON e.EmployeeID = L.EmployeeID LEFT JOIN TimeRecords AS t ON t.LogID = L.LogID Employee Table 1 e LogRecords Table 2 L TimeRecords Table 3 t
  • 24. Employee ID EmpName LogID EmployeeID LogDate TimeRecID LogID TIn TOut 01-054 Jerry Mendoza 1 01-054 11-09-11 1 1 09:00 18:03 01-054 Jerry Mendoza 3 01-054 11-11-11 3 3 9:02 18:34 01-055 Dane Sevilla Null Null Null Null Null Null Null 01-056 Mylene Antonio 2 01-056 11-10-11 2 2 7:30 16:55 NULL is returned where no there are no matches in the RIGHT table
  • 25. SELECT e.EmpName, L.LogDate, t.Tin, t.Tout FROM Employee AS e LEFTJOIN LogRecords AS L ON e.EmployeeID = L.EmployeeID LEFT JOIN TimeRecords AS t ON t.LogID = L.LogID EmpName LogDate TIn TOut Jerry Mendoza 11-09-11 09:00 18:03 Jerry Mendoza 11-11-11 9:02 18:34 Dane Sevilla Null Null Null Mylene Antonio 11-10-11 7:30 16:55
  • 26. SELECT e.EmpName, L.LogDate, t.Tin, t.Tout FROM Employee AS e LEFTJOIN LogRecords AS L ON e.EmployeeID = L.EmployeeID LEFT JOIN TimeRecords AS t ON t.LogID = L.LogID WHERE L.LogDate IS NOT NULL EmpName LogDate TIn TOut Jerry Mendoza 11-09-11 09:00 18:03 Jerry Mendoza 11-11-11 9:02 18:34 Mylene Antonio 11-10-11 7:30 16:55
  • 27. SELECT e.EmpName, L.LogDate, t.Tin, t.Tout FROM TimeRecords AS t RIGHT JOIN LogRecords AS L ON t.LogID = L.LogID RIGHT JOIN Employee AS e ON e.EmployeeID = L.EmployeeID EmpName LogDate TIn TOut Jerry Mendoza 11-09-11 09:00 18:03 Jerry Mendoza 11-11-11 9:02 18:34 Dane Sevilla Null Null Null Mylene Antonio 11-10-11 7:30 16:55
  • 28. In FULL JOIN, both tables are secondary (or optional). In this case, if we are matching rows in table A and B, then we display : all rows from table A even if there is no matching row in table B all rows from table B even if there is no matching row in table A TABLE A TABLE B
  • 29. Look at the tables below and note the common column names between them : GenreCode GenreDesc HR Horror RC Romance HS History CY Comedy SF Sci-Fi MovieID MovieTitle GenreCode 1 Saw 4 HR 2 Bad Teacher CY 3 The Notebook RC 4 Shrek No code available 5 Schindler’s List HS 6 The Exorcist HR TABLE 1 MovieList TABLE 2 GenresTable
  • 30. SELECT MovieTitle, GenreDesc FROM MovieList AS m FULLJOIN Genres AS g ON m.GenreCode = g.GenreCode MovieTitle GenreDesc Saw 4 Horror Bad Teacher Comedy The Notebook Romance Shrek NULL Schindler’s List History The Exorcist Horror NULL Sci-Fi
  • 31. JOIN’s are used to combine & get the data from different tables. INNER JOIN returns rows when there is a match in both tables. LEFT JOIN returns all rows from the left table, even if there are no matches in the right table. RIGHT JOIN returns all rows from the right table, even if there are no matches in the left table. FULL JOIN returns rows when there is a match in one of the tables.
  • 32. NULL values are returned in the output when no records are returned by an OUTER JOIN statement JOIN queries can be used with the conjunction of SELECT We can also use WHERE clauses along with JOIN’s
  • 33. Identify the type of JOIN shown in the following diagrams :
  • 34. Identify the following : 1. This is used to communicate with a database and lets you access and manipulate databases. 2. This is used to combine and get data from different tables. 3. This returns rows when there is a match in one of the tables.
  • 35. 4. This returns rows when there is a match in both tables. 5. This returns all rows from the left table, even if there are no matches in the right table. 6. This is where one or more objects called tables are contained. 7. This allows you to link data from two or more tables together into a single query result from one single SELECT statement
  • 36. 8. This returns all rows from the right table, even if there are no matches in the left table. 9. This is value returned in the output when no records are returned by an OUTER JOIN statement. 10. This conjunction can be used with JOIN queries.