8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel
8 2 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel In 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
8 3 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel In 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
8 4 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Relational 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
8 5 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel UNION Example query: –SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER UNION SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER_2;
8 6 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel UNION (continued)
8 7 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel UNION ALL Example query: –SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER UNION ALL SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER_2;
8 8 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel UNION ALL (continued)
8 9 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel INTERSECT
8 10 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel MINUS
8 11 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Syntax Alternatives
8 12 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Syntax Alternatives (continued)
8 13 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel SQL Join Operators
8 14 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Cross Join Syntax: –SELECT column-list FROM table1 CROSS JOIN table2
8 15 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Natural Join
8 16 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel JOIN USING Clause
8 17 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel JOIN ON Clause
8 18 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Outer 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
8 19 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Outer Joins (continued)
8 20 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Outer Joins (continued)
8 21 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Outer Joins (continued)
8 22 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Subqueries and Correlated Queries
8 23 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel WHERE Subqueries
8 24 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel IN Subqueries
8 25 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel HAVING Subqueries
8 26 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Multirow Subquery Operators: ANY and ALL
8 27 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel FROM Subqueries
8 28 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Attribute List Subqueries
8 29 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Attribute List Subqueries (continued)
8 30 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Correlated Subqueries
8 31 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Correlated Subqueries (continued)
8 32 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Date and Time Functions
8 33 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Date and Time Functions (continued)
8 34 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Date and Time Functions (continued)