Reading the Diagrams Used in This Book
Sample Databases Used in This Book
“Follow the Yellow Brick Road”
PART I: RELATIONAL DATABASES AND SQL
Chapter 1: What Is Relational?
Topics Covered in This Chapter
A Brief History of the Relational Model
Anatomy of a Relational Database
Chapter 2: Ensuring Your Database Structure Is Sound
Topics Covered in This Chapter
Why Worry about Sound Structures?
Resolving Unnecessary Duplicate Columns
Establishing Solid Relationships
Setting the Type of Participation
Setting the Degree of Participation
Chapter 3: A Concise History of SQL
Topics Covered in This Chapter
“… And Then There Was a Standard”
Evolution of the ANSI/ISO Standard
Which Version of SQL Does this Book Cover?
Chapter 4: Creating a Simple Query
Topics Covered in This Chapter
A Quick Aside: Data versus Information
Translating Your Request into SQL
Using a Shortcut to Request All Columns
First Things First: Collating Sequences
Chapter 5: Getting More Than Simple Columns
Topics Covered in This Chapter
What Type of Data Are You Trying to Express?
Changing Data Types: The CAST Function
Using Expressions in a SELECT Clause
Working with a Concatenation Expression
Working with a Mathematical Expression
Working with a Date Expression
A Brief Digression: Value Expressions
Chapter 6: Filtering Your Data
Topics Covered in This Chapter
Refining What You See Using WHERE
Checking for Overlapping Ranges
Nulls Revisited: A Cautionary Note
Expressing Conditions in Different Ways
PART III: WORKING WITH MULTIPLE TABLES
Topics Covered in This Chapter
Intersection between Result Sets
Problems You Can Solve with an Intersection
Difference between Result Sets
Problems You Can Solve with Difference
Combining Result Sets Using a Union
Problems You Can Solve with Union
Classic Set Operations versus SQL
Finding Common Values: INTERSECT
Finding Missing Values: EXCEPT (DIFFERENCE)
Topics Covered in This Chapter
Topics Covered in This Chapter
FULL OUTER JOIN on Non-Key Values
Find Partially Matched Information
Topics Covered in This Chapter
Using Simple SELECT Statements
Combining Complex SELECT Statements
Topics Covered in This Chapter
Subqueries as Column Expressions
An Introduction to Aggregate Functions: COUNT and MAX
Special Predicate Keywords for Subqueries
Build Subqueries as Column Expressions
PART IV: SUMMARIZING AND GROUPING DATA
Topics Covered in This Chapter
Counting Rows and Values with COUNT
Calculating a Mean Value with AVG
Finding the Largest Value with MAX
Finding the Smallest Value with MIN
Using Aggregate Functions in Filters
Topics Covered in This Chapter
Mixing Columns and Expressions
Using GROUP BY in a Subquery in a WHERE Clause
Simulating a SELECT DISTINCT Statement
Chapter 14: Filtering Grouped Data
Topics Covered in This Chapter
A New Meaning for “Focus Groups”
Where You Filter Makes a Difference
Should You Filter in WHERE or in HAVING?
Avoiding the HAVING COUNT Trap
PART V: MODIFYING SETS OF DATA
Chapter 15: Updating Sets of Data
Topics Covered in This Chapter
Using a Simple UPDATE Expression
Using a Subquery to Filter Rows
Some Database Systems Allow a JOIN in the UPDATE Clause
Using a Subquery UPDATE Expression
Chapter 16: Inserting Sets of Data
Topics Covered in This Chapter
Generating the Next Primary Key Value
Inserting Data by Using SELECT
Chapter 17: Deleting Sets of Data
Topics Covered in This Chapter
PART VI: INTRODUCTION TO SOLVING TOUGH PROBLEMS
Chapter 18: “NOT” and “AND” Problems
Topics Covered in This Chapter
Sets with Multiple AND Criteria
Sets with Multiple NOT Criteria
Sets Including Some Criteria but Excluding Others
Finding Multiple Matches in the Same Table
Topics Covered in This Chapter
Conditional Expressions (CASE)
Solving Problems with Simple CASE
Solving Problems with Searched CASE
Chapter 20: Using Unlinked Data and “Driver” Tables
Topics Covered in This Chapter
Deciding When to Use a CROSS JOIN
Solving Problems with Unlinked Data
Solving Problems Using “Driver” Tables
Examples Using Unlinked Tables
Chapter 21: Performing Complex Calculations on Groups
Getting Totals in a Hierarchy Using Rollup
Calculating Totals on Combinations Using CUBE
Creating a Union of Totals with GROUPING SETS
Variations on Grouping Techniques
Chapter 22: Partitioning Data into Windows
What You Can Do With a “Window” into Your Data
Using Windows with Aggregate Functions
Examples Using RANK, DENSE_RANK, and PERCENT_RANK
Examples Using Aggregate Functions
Appendix A: SQL Standard Diagrams
Appendix B: Schema for the Sample Databases
Entertainment Agency Example Database
Entertainment Agency Modify Database
School Scheduling Example Database
School Scheduling Modify Database
Bowling League Example Database
Bowling League Modify Database