SlideShare a Scribd company logo
Chapter - 4

Displaying Data
from Multiple Tables
Joins
Obtaining Data from Multiple Tables
Cartesian Products


When a join condition is invalid or omitted completely, the result is a
Cartesian product, in which all combinations of rows are displayed.



All rows in the first table are joined to all rows in the second table.



A Cartesian product tends to generate a large number of rows, and the
result is rarely useful.



You should always include a valid join condition in a WHERE clause, unless
you have a specific need to combine all rows from all tables.



Cartesian products are useful for some tests when you need to generate a
large number of rows to simulate a reasonable amount of data.
Types of Joins
Joining Tables Using Oracle Syntax


Use a join to query data from more than one table.



Write the join condition in the WHERE clause.



Prefix the column name with the table name when the same column
name appears in more than one table.
Defining Joins
Guidelines






When data from more than one
table in the database is required, a
join condition is used.
Rows in one table can be joined to
rows in another table according to
common values existing in
corresponding columns, that is,
usually primary and foreign key
columns.
To display data from two or more
related tables, write a simple join
condition in the WHERE clause.



When writing a SELECT statement that
joins tables, precede the column name with
the table name for clarity and to enhance
database access.



If the same column name appears in more
than one table, the column name must be
prefixed with the table name.



To join n tables together, you need a
minimum of n-1 join conditions.



For example, to join four tables, a minimum
of three joins is required.



This rule may not apply if your table has a
concatenated primary key, in which case
more than one column is required to
uniquely identify each row.
What is an Equi-join?
Equijoins


To determine an employee’s department name, you compare the
value in the DEPARTMENT_ID column in the EMPLOYEES table
with the DEPARTMENT_ID values in the DEPARTMENTS table.



The relationship between the EMPLOYEES and DEPARTMENTS
tables is an equijoin—that is, values in the DEPARTMENT_ID
column on both tables must be equal.



Frequently, this type of join involves primary and foreign key
complements.



Note: Equijoins are also called simple joins or inner joins.
Decision Matrix


Explain the use of a decision matrix for simplifying writing joins.



For example, if you want to display the name and department number of all the
employees who are in the same department as Goyal, you can start by making the
following decision tree:



Now the SQL statement can be easily formulated by looking at the decision matrix.



The first column gives the column list in the SELECT statement, the second column
gives the tables for the FROM clause, and the third column gives the condition for the
WHERE clause.
Qualifying Ambiguous Column Names
Guidelines
Table aliases can be max. up to 30
characters in length, but shorter is
better.





Use table prefixes to qualify column
names that are in multiple tables.






If a table alias is used for a particular
table name in the FROM clause, then
that table alias must be substituted for
the table name throughout the
SELECT statement.



Table aliases should be meaningful.



The table alias is valid only for the
current SELECT statement.

Distinguish columns that have identical
names but reside in different tables by
using column aliases.

Using Table Aliases


Simplify queries by using table aliases.



Improve performance by using table
prefixes.
Joining More than Two Tables
Non-Equijoins
A non-equijoin is a join condition containing something other than an equality operator.
Outer Joins
Outer Joins Syntax


You use an outer join to also see rows that do not meet the join condition.



The Outer join operator is the plus sign (+).

(+) is placed on the “side” of the join that is deficient in information.
Self Joins


Sometimes you need to join a table to itself.
Joining Tables Using SQL: 1999 Syntax











table1.column
CROSS JOIN
NATURAL JOIN
JOIN table
USING
JOIN table ON
table1.column_name
= table2.column_name
LEFT/RIGHT/FULL OUTER

Denotes the table and column from which data is retrieved
Returns a Cartesian product from the two tables
Joins two tables based on the same column name
column_name Performs an equijoin based on the column name
Performs an equijoin based on the condition in the ON clause
Creating Cross Joins


The CROSS JOIN clause produces the cross product of two tables.



This is the same as a Cartesian product between the two tables.
Creating Natural Joins


The NATURAL JOIN clause is based on all columns in the two tables that have the same name.



It selects rows from the two tables that have equal values in all matched columns.



If the columns having the same names have different data types, an error is returned.
Creating Joins with the USING Clause


If several columns have the same names but the data types do not match, the NATURAL JOIN
clause can be modified with the USING clause to specify the columns that should be used for an
equi-join.



Use the USING clause to match only one column when more than one column matches.



Do not use a table name or alias in the referenced columns.



The NATURAL JOIN and USING clauses are mutually exclusive.
Creating Joins with the ON Clause


The join condition for the natural join is basically an equi-join of all columns with the same name.



To specify arbitrary conditions or specify columns to join, the ON clause is used.



The join condition is separated from other search conditions.



The ON clause makes code easy to understand.
Creating Three-Way Joins with the ON Clause
INNER Joins Versus OUTER Joins


In SQL: 1999, the join of two tables returning only matched rows is an
inner join.



A join between two tables that returns the results of the inner join as well as
unmatched rows left (or right) tables is a left (or right) outer join.



A join between two tables that returns the results of an inner join as well as
the results of a left and right join is a full outer join.
Joins - Comparing SQL: 1999 to Oracle Syntax
LEFT OUTER JOIN


This query retrieves all rows in the EMPLOYEES table, which is the left table even if
there is no match in the DEPARTMENTS table.

This query was completed in earlier releases as follows:
SELECT e.last_name, e.department_id, d.department_name
FROM employees e, departments d
WHERE d.department_id (+) = e.department_id;
RIGHT OUTER JOIN


This query retrieves all rows in the DEPARTMENTS table, which is the right table
even if there is no match in the EMPLOYEES table.

This query was completed in earlier releases as follows:
SELECT e.last_name,e.department_id,d.department_name
FROM employees e, departments d
WHERE d.department_id = e.department_id (+);
FULL OUTER JOIN


This query retrieves all rows in the EMPLOYEES table, even if there is no match in the
DEPARTMENTS table. It also retrieves all rows in the DEPARTMENTS table, even if there is no
match in the EMPLOYEES table.



It was not possible to complete this in earlier releases using outer joins. However, you could
accomplish the same results using the UNION operator.

SELECT e.last_name, e.department_id, d.department_name
FROM employees e, departments d
WHERE e.department_id (+) = d.department_id
UNION
SELECT e.last_name, e.department_id, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id (+);
Additional Conditions
Summary


There are multiple ways to join tables.

Types of Joins








Equijoins
Non-equijoins
Outer joins
Self joins
Cross joins
Natural joins
Full or outer joins

Cartesian Products
A Cartesian product results in all combinations of rows displayed. This is done by either omitting the WHERE
clause or specifying the CROSS JOIN clause.
Table Aliases



Table aliases speed up database access.
Table aliases can help to keep SQL code smaller, by conserving memory.

More Related Content

What's hot

Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
Punjab University
 
Join
JoinJoin
Codd's rules
Codd's rulesCodd's rules
Codd's rulesMohd Arif
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Naimul Arif
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
Steve Johnson
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
Join query
Join queryJoin query
Join query
Waqar Ali
 
normalization-1.pptx
normalization-1.pptxnormalization-1.pptx
normalization-1.pptx
AbhishekJohnCharan1
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
PRAKHAR JHA
 
SQL
SQLSQL
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
VARSHAKUMARI49
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In SqlAnurag
 
Mapping ER and EER Model
Mapping ER and EER ModelMapping ER and EER Model
Mapping ER and EER Model
Mary Brinda
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
Syed Zaid Irshad
 

What's hot (20)

Sql join
Sql  joinSql  join
Sql join
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Join
JoinJoin
Join
 
Codd's rules
Codd's rulesCodd's rules
Codd's rules
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
MySQL Data types
MySQL Data typesMySQL Data types
MySQL Data types
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Join query
Join queryJoin query
Join query
 
normalization-1.pptx
normalization-1.pptxnormalization-1.pptx
normalization-1.pptx
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
SQL
SQLSQL
SQL
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Mapping ER and EER Model
Mapping ER and EER ModelMapping ER and EER Model
Mapping ER and EER Model
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Trigger
TriggerTrigger
Trigger
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Viewers also liked

Introducción Procesador Consultas SQL Server - Query Processor
Introducción Procesador Consultas SQL Server - Query ProcessorIntroducción Procesador Consultas SQL Server - Query Processor
Introducción Procesador Consultas SQL Server - Query Processor
Eduardo Castro
 
Taller básico de JOINS, SUBQUERYING, APPLY, CTE
Taller básico de JOINS, SUBQUERYING, APPLY, CTETaller básico de JOINS, SUBQUERYING, APPLY, CTE
Taller básico de JOINS, SUBQUERYING, APPLY, CTE
Julián Castiblanco
 
Curso SQL - Leccion 7
Curso SQL - Leccion 7  Curso SQL - Leccion 7
Curso SQL - Leccion 7
Emmanuel Ortiz Gutierrez
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
Paul Harkins
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
Brian Gallagher
 
Inner join
Inner joinInner join
Inner join
Israel Rey
 

Viewers also liked (9)

Cap 7. oracle SQL fundamentals
Cap 7. oracle SQL fundamentalsCap 7. oracle SQL fundamentals
Cap 7. oracle SQL fundamentals
 
Join
JoinJoin
Join
 
Introducción Procesador Consultas SQL Server - Query Processor
Introducción Procesador Consultas SQL Server - Query ProcessorIntroducción Procesador Consultas SQL Server - Query Processor
Introducción Procesador Consultas SQL Server - Query Processor
 
Join
JoinJoin
Join
 
Taller básico de JOINS, SUBQUERYING, APPLY, CTE
Taller básico de JOINS, SUBQUERYING, APPLY, CTETaller básico de JOINS, SUBQUERYING, APPLY, CTE
Taller básico de JOINS, SUBQUERYING, APPLY, CTE
 
Curso SQL - Leccion 7
Curso SQL - Leccion 7  Curso SQL - Leccion 7
Curso SQL - Leccion 7
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Inner join
Inner joinInner join
Inner join
 

Similar to Join sql

Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
uzmasulthana3
 
Joins.ppt
Joins.pptJoins.ppt
Joins.ppt
UmangThakkar26
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
Achmad Solichin
 
Les05
Les05Les05
Assignment 3
Assignment 3Assignment 3
Assignment 3
SneaK3
 
App C
App CApp C
1 introduction to my sql
1 introduction to my sql1 introduction to my sql
1 introduction to my sql
Prof. Erwin Globio
 
Displaying data from multiple tables
Displaying data from multiple tablesDisplaying data from multiple tables
Displaying data from multiple tables
Syed Zaid Irshad
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptx
KrishnansuSenapati
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
Balqees Al.Mubarak
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
e computer notes - From multiple tables
e computer notes - From multiple tablese computer notes - From multiple tables
e computer notes - From multiple tablesecomputernotes
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2
Techglyphs
 
SQL COMMANDS WITH EXAMPLES.pptx
SQL COMMANDS WITH EXAMPLES.pptxSQL COMMANDS WITH EXAMPLES.pptx
SQL COMMANDS WITH EXAMPLES.pptx
Bikalpa Thapa
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
ASHABOOPATHY
 

Similar to Join sql (20)

Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
 
Joins.ppt
Joins.pptJoins.ppt
Joins.ppt
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
 
Les05
Les05Les05
Les05
 
Les04
Les04Les04
Les04
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
App C
App CApp C
App C
 
1 introduction to my sql
1 introduction to my sql1 introduction to my sql
1 introduction to my sql
 
Displaying data from multiple tables
Displaying data from multiple tablesDisplaying data from multiple tables
Displaying data from multiple tables
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptx
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
 
Sql slid
Sql slidSql slid
Sql slid
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
e computer notes - From multiple tables
e computer notes - From multiple tablese computer notes - From multiple tables
e computer notes - From multiple tables
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2
 
SQL COMMANDS WITH EXAMPLES.pptx
SQL COMMANDS WITH EXAMPLES.pptxSQL COMMANDS WITH EXAMPLES.pptx
SQL COMMANDS WITH EXAMPLES.pptx
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 

More from Vikas Gupta

SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 
Sql DML
Sql DMLSql DML
Sql DML
Vikas Gupta
 
Sql DML
Sql DMLSql DML
Sql DML
Vikas Gupta
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
Vikas Gupta
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 

More from Vikas Gupta (6)

SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Sql DML
Sql DMLSql DML
Sql DML
 
Sql DML
Sql DMLSql DML
Sql DML
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Sql intro
Sql introSql intro
Sql intro
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Join sql

  • 1. Chapter - 4 Displaying Data from Multiple Tables Joins
  • 2. Obtaining Data from Multiple Tables
  • 3. Cartesian Products  When a join condition is invalid or omitted completely, the result is a Cartesian product, in which all combinations of rows are displayed.  All rows in the first table are joined to all rows in the second table.  A Cartesian product tends to generate a large number of rows, and the result is rarely useful.  You should always include a valid join condition in a WHERE clause, unless you have a specific need to combine all rows from all tables.  Cartesian products are useful for some tests when you need to generate a large number of rows to simulate a reasonable amount of data.
  • 4.
  • 6. Joining Tables Using Oracle Syntax  Use a join to query data from more than one table.  Write the join condition in the WHERE clause.  Prefix the column name with the table name when the same column name appears in more than one table.
  • 7. Defining Joins Guidelines    When data from more than one table in the database is required, a join condition is used. Rows in one table can be joined to rows in another table according to common values existing in corresponding columns, that is, usually primary and foreign key columns. To display data from two or more related tables, write a simple join condition in the WHERE clause.  When writing a SELECT statement that joins tables, precede the column name with the table name for clarity and to enhance database access.  If the same column name appears in more than one table, the column name must be prefixed with the table name.  To join n tables together, you need a minimum of n-1 join conditions.  For example, to join four tables, a minimum of three joins is required.  This rule may not apply if your table has a concatenated primary key, in which case more than one column is required to uniquely identify each row.
  • 8. What is an Equi-join?
  • 9. Equijoins  To determine an employee’s department name, you compare the value in the DEPARTMENT_ID column in the EMPLOYEES table with the DEPARTMENT_ID values in the DEPARTMENTS table.  The relationship between the EMPLOYEES and DEPARTMENTS tables is an equijoin—that is, values in the DEPARTMENT_ID column on both tables must be equal.  Frequently, this type of join involves primary and foreign key complements.  Note: Equijoins are also called simple joins or inner joins.
  • 10. Decision Matrix  Explain the use of a decision matrix for simplifying writing joins.  For example, if you want to display the name and department number of all the employees who are in the same department as Goyal, you can start by making the following decision tree:  Now the SQL statement can be easily formulated by looking at the decision matrix.  The first column gives the column list in the SELECT statement, the second column gives the tables for the FROM clause, and the third column gives the condition for the WHERE clause.
  • 11. Qualifying Ambiguous Column Names Guidelines Table aliases can be max. up to 30 characters in length, but shorter is better.   Use table prefixes to qualify column names that are in multiple tables.    If a table alias is used for a particular table name in the FROM clause, then that table alias must be substituted for the table name throughout the SELECT statement.  Table aliases should be meaningful.  The table alias is valid only for the current SELECT statement. Distinguish columns that have identical names but reside in different tables by using column aliases. Using Table Aliases  Simplify queries by using table aliases.  Improve performance by using table prefixes.
  • 12. Joining More than Two Tables
  • 13. Non-Equijoins A non-equijoin is a join condition containing something other than an equality operator.
  • 15. Outer Joins Syntax  You use an outer join to also see rows that do not meet the join condition.  The Outer join operator is the plus sign (+). (+) is placed on the “side” of the join that is deficient in information.
  • 16. Self Joins  Sometimes you need to join a table to itself.
  • 17. Joining Tables Using SQL: 1999 Syntax          table1.column CROSS JOIN NATURAL JOIN JOIN table USING JOIN table ON table1.column_name = table2.column_name LEFT/RIGHT/FULL OUTER Denotes the table and column from which data is retrieved Returns a Cartesian product from the two tables Joins two tables based on the same column name column_name Performs an equijoin based on the column name Performs an equijoin based on the condition in the ON clause
  • 18. Creating Cross Joins  The CROSS JOIN clause produces the cross product of two tables.  This is the same as a Cartesian product between the two tables.
  • 19. Creating Natural Joins  The NATURAL JOIN clause is based on all columns in the two tables that have the same name.  It selects rows from the two tables that have equal values in all matched columns.  If the columns having the same names have different data types, an error is returned.
  • 20. Creating Joins with the USING Clause  If several columns have the same names but the data types do not match, the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an equi-join.  Use the USING clause to match only one column when more than one column matches.  Do not use a table name or alias in the referenced columns.  The NATURAL JOIN and USING clauses are mutually exclusive.
  • 21. Creating Joins with the ON Clause  The join condition for the natural join is basically an equi-join of all columns with the same name.  To specify arbitrary conditions or specify columns to join, the ON clause is used.  The join condition is separated from other search conditions.  The ON clause makes code easy to understand.
  • 22. Creating Three-Way Joins with the ON Clause
  • 23. INNER Joins Versus OUTER Joins  In SQL: 1999, the join of two tables returning only matched rows is an inner join.  A join between two tables that returns the results of the inner join as well as unmatched rows left (or right) tables is a left (or right) outer join.  A join between two tables that returns the results of an inner join as well as the results of a left and right join is a full outer join.
  • 24. Joins - Comparing SQL: 1999 to Oracle Syntax
  • 25. LEFT OUTER JOIN  This query retrieves all rows in the EMPLOYEES table, which is the left table even if there is no match in the DEPARTMENTS table. This query was completed in earlier releases as follows: SELECT e.last_name, e.department_id, d.department_name FROM employees e, departments d WHERE d.department_id (+) = e.department_id;
  • 26. RIGHT OUTER JOIN  This query retrieves all rows in the DEPARTMENTS table, which is the right table even if there is no match in the EMPLOYEES table. This query was completed in earlier releases as follows: SELECT e.last_name,e.department_id,d.department_name FROM employees e, departments d WHERE d.department_id = e.department_id (+);
  • 27. FULL OUTER JOIN  This query retrieves all rows in the EMPLOYEES table, even if there is no match in the DEPARTMENTS table. It also retrieves all rows in the DEPARTMENTS table, even if there is no match in the EMPLOYEES table.  It was not possible to complete this in earlier releases using outer joins. However, you could accomplish the same results using the UNION operator. SELECT e.last_name, e.department_id, d.department_name FROM employees e, departments d WHERE e.department_id (+) = d.department_id UNION SELECT e.last_name, e.department_id, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id (+);
  • 29. Summary  There are multiple ways to join tables. Types of Joins        Equijoins Non-equijoins Outer joins Self joins Cross joins Natural joins Full or outer joins Cartesian Products A Cartesian product results in all combinations of rows displayed. This is done by either omitting the WHERE clause or specifying the CROSS JOIN clause. Table Aliases   Table aliases speed up database access. Table aliases can help to keep SQL code smaller, by conserving memory.