Академический Документы
Профессиональный Документы
Культура Документы
ADVANCED SQL
Modern Database Management
11th Edition
OBJECTIVES
Define terms
Write single and multiple table SQL queries
Define and use three types of joins
Write noncorrelated and correlated subqueries
Understand and use SQL in procedural
languages (e.g. PHP, PL/SQL)
Understand triggers and stored procedures
Discuss SQL:2008 standard and its
enhancements and extensions
Chapter 7
The common columns in joined tables are usually the primary key
of the dominant table and the foreign key of the dependent table in
1:M relationships.
Chapter 7
Outer
Union
Chapter 7
Figure 7-2
Visualization of different join types with results returned
in shaded area
Chapter 7
Chapter 7
EQUI-JOIN EXAMPLE
Customer ID
appears twice in the
result
Chapter 7
Chapter 7
10
11
Outer Join
Results
Unlike
INNER join,
this will
include
customer
rows with no
matching
order rows
Chapter 7
12
Four tables
involved in
this join
Chapter 7
13
14
SELF-JOIN EXAMPLE
15
Chapter 7
16
Chapter 7
17
SUBQUERY EXAMPLE
Chapter 7
18
Subquery version
Chapter 7
19
Chapter 7
20
Chapter 7
21
Noncorrelated
Do
subqueries:
Correlated
Make
subqueries:
Chapter 7
22
Chapter 7
23
Chapter 7
24
Figure 7-8b
Processing a
correlated
subquery
Chapter 7
25
The WHERE clause normally cannot include aggregate functions, but because
the aggregate is performed in the subquery its result can be used in the outer
querys WHERE clause.
Chapter 7
26
UNION QUERIES
Combine
Second query
Chapter 7
27
Note: With
UNION queries,
the quantity and
data types of the
attributes in the
SELECT clauses
of both queries
must be identical.
Chapter 7
28
Chapter 7
29
Chapter 7
30
Chapter 7
31
Chapter 7
32
Chapter 7
33
Chapter 7
34
Chapter 7
35
Chapter 7
36
SQL:2008
ENHANCEMENTS/EXTENSIONS
Chapter 7
37
SQL:2008 ENHANCEMENTS
(CONT)
Programming extensions
Persistent Stored Modules (SQL/PSM)
Capability
Chapter 7
38
Routines
Program
Chapter 7
39
Chapter 7
40
Chapter 7
41
Chapter 7
42
Embedded
Including
SQL
Dynamic
Ability
SQL
Chapter 7
43
44