Professional Documents
Culture Documents
CSCS- 213
By:
Shahid Mahmood
Warning!
Lecture slides are high-level description
of lectures
Nested Query
SQL statements for Accessing
Multiple Tables
o Such statements might require:
- Cartesian Product
- Inner join
- Outer join
- Semi join
- Natural join
SQL statements for Accessing
Multiple Tables
o Cartesian Product: SQL uses SELECT command for
Cartesian product by using names of the tables
involved.
It Produces m X n rows
E.g.,
Using Alias:
ON c. PrName = p. PrName
SQL statements for Accessing
Multiple Tables
o Inner Join with WHERE clause
E.g.,
WHERE
Left outer join: Inner join plus rows from the non-matching
rows from the left table
Right outer join: Inner join plus rows from the non-
matching rows from the right table
Full outer join: Inner join plus the non-matching rows from
both tables
SQL statements for Accessing
Multiple Tables
o Outer Join:
e.g.,
Select *
from
COURSE c
PROGRAM p
ON c. PrName = p. PrName
Outer join (Left-outer Join)
Invoice
PAYMENT
20 1 5-3-10 200 - - -
SQL statements for Accessing
Multiple Tables
o Semi Join: First inner join and then projected on the
attributes of one table.
e.g.,
from
ON p.PrName = c.PrName
SQL statements for Accessing
Multiple Tables
o Self Join: A table making relationship with itself
e.g.,
from
Student a, student b
Sub Queries
It is a query with in a query
e.g.,