Title: Advanced SQL
1Chapter 8
Advanced SQL Database Systems Design,
Implementation, and Management, Seventh Edition,
Rob and Coronel
2In this chapter, you will learn
- About the relational set operators UNION, UNION
ALL, INTERSECT, and MINUS - How to use the advanced SQL JOIN operator syntax
- About the different types of subqueries and
correlated queries - How to use SQL functions to manipulate dates,
strings, and other data
3In this chapter, you will learn (continued)
- How to create and use updatable views
- How to create and use triggers and stored
procedures - How to create embedded SQL
4Relational Set Operators
- UNION
- INTERSECT
- MINUS
- Work properly if relations are union-compatible
- Names of relation attributes must be the same and
their data types must be identical
5UNION
- Example query
- SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL,
CUS_AREACODE, CUS_PHONEFROM
CUSTOMERUNIONSELECT CUS_LNAME, CUS_FNAME,
CUS_INITIAL, CUS_AREACODE, CUS_PHONEFROM
CUSTOMER_2
6UNION (continued)
7UNION ALL
- Example query
- SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL,
CUS_AREACODE, CUS_PHONEFROM CUSTOMERUNION
ALLSELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL,
CUS_AREACODE, CUS_PHONEFROM CUSTOMER_2
8UNION ALL (continued)
9INTERSECT
10MINUS
11Syntax Alternatives
12Syntax Alternatives (continued)
13SQL Join Operators
14Cross Join
- Syntax
- SELECT column-list FROM table1 CROSS JOIN table2
15Natural Join
16JOIN USING Clause
17JOIN ON Clause
18Outer Joins
- Returns not only matching rows, but also rows
with unmatched attribute values for one table or
both tables to be joined - Three types
- Left
- Right
- Full
19Outer Joins (continued)
20Outer Joins (continued)
21Outer Joins (continued)
22Subqueries and Correlated Queries
23WHERE Subqueries
24IN Subqueries
25HAVING Subqueries
26Multirow Subquery Operators ANY and ALL
27FROM Subqueries
28Attribute List Subqueries
29Attribute List Subqueries (continued)
30Correlated Subqueries
31Correlated Subqueries (continued)
32Date and Time Functions
33Date and Time Functions (continued)
34Date and Time Functions (continued)