| Foreword |
|
xiii | |
| Preface and Acknowledgments |
|
xv | |
| About the Authors |
|
xix | |
| Introduction |
|
xxiii | |
| Are You a ``Mere Mortal''? |
|
xxiii | |
| About This Book |
|
xxiv | |
| How to Use This Book |
|
xxv | |
| Reading the Diagrams Used in This Book |
|
xxvi | |
| Sample Databases Used in This Book |
|
xxx | |
| ``Follow the Yellow Brick Road'' |
|
xxxi | |
| PART I Relational Databases and SQL |
|
1 | (64) |
|
|
|
3 | (16) |
|
Topics Covered in This Chapter |
|
|
3 | (1) |
|
|
|
3 | (1) |
|
A Brief History of the Relational Model |
|
|
4 | (2) |
|
|
|
4 | (1) |
|
Relational Databases Software |
|
|
5 | (1) |
|
Anatomy of a Relational Database |
|
|
6 | (9) |
|
|
|
6 | (1) |
|
|
|
7 | (1) |
|
|
|
8 | (1) |
|
|
|
8 | (2) |
|
|
|
10 | (1) |
|
|
|
10 | (5) |
|
|
|
15 | (2) |
|
``Where Do I Go from Here?'' |
|
|
16 | (1) |
|
|
|
17 | (2) |
|
Ensuring Your Database Structure Is Sound |
|
|
19 | (32) |
|
Topics Covered in This Chapter |
|
|
19 | (1) |
|
Why Is This Chapter Here? |
|
|
19 | (1) |
|
Why Worry about Sound Structures? |
|
|
20 | (1) |
|
|
|
21 | (8) |
|
What's in a Name? (Part One) |
|
|
21 | (2) |
|
Smoothing Out the Rough Edges |
|
|
23 | (2) |
|
Resolving Multipart Fields |
|
|
25 | (2) |
|
Resolving Multivalued Fields |
|
|
27 | (2) |
|
|
|
29 | (12) |
|
What's in a Name? (Part Two) |
|
|
29 | (2) |
|
Ensuring a Sound Structure |
|
|
31 | (2) |
|
Resolving Unnecessary Duplicate Fields |
|
|
33 | (4) |
|
Identification Is the Key |
|
|
37 | (4) |
|
Establishing Solid Relationships |
|
|
41 | (7) |
|
Establishing a Deletion Rule |
|
|
43 | (2) |
|
Setting the Type of Participation |
|
|
45 | (1) |
|
Setting the Degree of Participation |
|
|
45 | (3) |
|
|
|
48 | (1) |
|
|
|
49 | (2) |
|
|
|
51 | (14) |
|
Topics Covered in This Chapter |
|
|
51 | (1) |
|
|
|
52 | (1) |
|
Early Vendor Implementations |
|
|
53 | (1) |
|
``...And Then There Was a Standard'' |
|
|
54 | (2) |
|
Evolution of the ANSI/ISO Standard |
|
|
56 | (4) |
|
|
|
59 | (1) |
|
Commercial Implementations |
|
|
60 | (1) |
|
|
|
60 | (1) |
|
Why Should You Learn SQL? |
|
|
61 | (2) |
|
|
|
63 | (2) |
| PART II SQL Basics |
|
65 | (134) |
|
|
|
67 | (32) |
|
Topics Covered in This Chapter |
|
|
67 | (1) |
|
|
|
67 | (1) |
|
|
|
68 | (3) |
|
Major Clauses in a Select Statement |
|
|
69 | (2) |
|
A Quick Aside: Data vs. Information |
|
|
71 | (1) |
|
Translating Your Request into SQL |
|
|
72 | (8) |
|
Expanding the Field of Vision |
|
|
77 | (3) |
|
Eliminating Duplicate Rows |
|
|
80 | (2) |
|
|
|
82 | (4) |
|
First Things First: Collating Sequences |
|
|
83 | (1) |
|
|
|
83 | (3) |
|
|
|
86 | (1) |
|
|
|
87 | (9) |
|
|
|
96 | (1) |
|
Problems for You to Solve |
|
|
97 | (2) |
|
Getting More Than Simple Columns |
|
|
99 | (44) |
|
Topics Covered in This Chapter |
|
|
99 | (1) |
|
The Select Clause: Take Two |
|
|
100 | (5) |
|
Specifying Explicit Values |
|
|
101 | (4) |
|
Moving Beyond Basic Information |
|
|
105 | (1) |
|
|
|
105 | (1) |
|
What Are You Trying to Express? |
|
|
106 | (2) |
|
|
|
106 | (2) |
|
|
|
108 | (11) |
|
|
|
109 | (4) |
|
|
|
113 | (3) |
|
|
|
116 | (3) |
|
Using Expressions in a Select Clause |
|
|
119 | (8) |
|
A Brief Digression: Value Expressions |
|
|
125 | (2) |
|
That ``Nothing'' Value---Null |
|
|
127 | (4) |
|
|
|
128 | (3) |
|
|
|
131 | (8) |
|
|
|
139 | (2) |
|
Problems for You to Solve |
|
|
141 | (2) |
|
|
|
143 | (56) |
|
Topics Covered in This Chapter |
|
|
143 | (1) |
|
Refining What You See Using Where |
|
|
144 | (4) |
|
|
|
144 | (2) |
|
|
|
146 | (2) |
|
Defining Search Conditions |
|
|
148 | (22) |
|
|
|
148 | (8) |
|
|
|
156 | (3) |
|
|
|
159 | (2) |
|
|
|
161 | (4) |
|
|
|
165 | (2) |
|
|
|
167 | (3) |
|
Using Multiple Conditions |
|
|
170 | (13) |
|
|
|
170 | (6) |
|
|
|
176 | (2) |
|
|
|
178 | (5) |
|
Nulls Revisited: A Cautionary Note |
|
|
183 | (4) |
|
Expressing Conditions in Different Ways |
|
|
187 | (1) |
|
|
|
188 | (7) |
|
|
|
195 | (1) |
|
Problems for You to Solve |
|
|
196 | (3) |
| PART III Working with Multiple Tables |
|
199 | (186) |
|
|
|
201 | (32) |
|
Topics Covered in This Chapter |
|
|
201 | (1) |
|
|
|
202 | (1) |
|
|
|
203 | (1) |
|
|
|
204 | (6) |
|
Intersection in Set Theory |
|
|
204 | (1) |
|
Intersection between Result Sets |
|
|
205 | (3) |
|
Problems You Can Solve with Intersect |
|
|
208 | (2) |
|
|
|
210 | (7) |
|
|
|
210 | (2) |
|
Difference between Result Sets |
|
|
212 | (4) |
|
Problems You Can Solve with Difference |
|
|
216 | (1) |
|
|
|
217 | (5) |
|
|
|
217 | (2) |
|
Combining Result Sets Using Union |
|
|
219 | (2) |
|
Problems You Can Solve with Union |
|
|
221 | (1) |
|
|
|
222 | (9) |
|
``Classical'' Set Operations vs. SQL |
|
|
222 | (1) |
|
Finding Common Values---Intersect |
|
|
222 | (4) |
|
Finding Missing Values---Except (Difference) |
|
|
226 | (2) |
|
|
|
228 | (3) |
|
|
|
231 | (2) |
|
|
|
233 | (42) |
|
Topics Covered in This Chapter |
|
|
233 | (1) |
|
|
|
233 | (1) |
|
|
|
234 | (16) |
|
What's ``Legal'' to Join? |
|
|
234 | (1) |
|
|
|
235 | (14) |
|
Check Those Relationships! |
|
|
249 | (1) |
|
|
|
250 | (2) |
|
|
|
250 | (1) |
|
|
|
251 | (1) |
|
|
|
252 | (19) |
|
|
|
252 | (5) |
|
|
|
257 | (6) |
|
Looking for Matching Values |
|
|
263 | (8) |
|
|
|
271 | (1) |
|
Problems for You to Solve |
|
|
272 | (3) |
|
|
|
275 | (42) |
|
Topics Covered in This Chapter |
|
|
275 | (1) |
|
|
|
275 | (2) |
|
The Left/Right Outer Join |
|
|
277 | (18) |
|
|
|
278 | (17) |
|
|
|
295 | (4) |
|
|
|
296 | (2) |
|
Full Outer Join on Non-Key Values |
|
|
298 | (1) |
|
|
|
299 | (1) |
|
|
|
299 | (2) |
|
|
|
300 | (1) |
|
Find Partially Matched Information |
|
|
300 | (1) |
|
|
|
301 | (12) |
|
|
|
313 | (1) |
|
Problems for You to Solve |
|
|
314 | (3) |
|
|
|
317 | (28) |
|
Topics Covered in This Chapter |
|
|
317 | (1) |
|
|
|
317 | (3) |
|
Writing Requests with Union |
|
|
320 | (10) |
|
Using Simple Select Statements |
|
|
320 | (3) |
|
Combining Complex Select Statements |
|
|
323 | (3) |
|
Using Union More Than Once |
|
|
326 | (2) |
|
|
|
328 | (2) |
|
|
|
330 | (1) |
|
|
|
331 | (11) |
|
|
|
342 | (1) |
|
Problems for You to Solve |
|
|
342 | (3) |
|
|
|
345 | (40) |
|
Topics Covered in This Chapter |
|
|
345 | (1) |
|
|
|
346 | (2) |
|
|
|
346 | (1) |
|
|
|
347 | (1) |
|
|
|
347 | (1) |
|
Subqueries as Column Expressions |
|
|
348 | (5) |
|
|
|
348 | (3) |
|
An Introduction to Aggregate Functions---Count and Max |
|
|
351 | (2) |
|
|
|
353 | (13) |
|
|
|
353 | (2) |
|
Special Predicate Keywords for Subqueries |
|
|
355 | (11) |
|
|
|
366 | (2) |
|
|
|
366 | (1) |
|
|
|
366 | (2) |
|
|
|
368 | (12) |
|
Subqueries in Expressions |
|
|
369 | (5) |
|
|
|
374 | (6) |
|
|
|
380 | (1) |
|
Problems for You to Solve |
|
|
381 | (4) |
| PART IV Summarizing and Grouping Data |
|
385 | (82) |
|
|
|
387 | (26) |
|
Topics Covered in This Chapter |
|
|
387 | (1) |
|
|
|
388 | (12) |
|
Counting Rows and Values with Count |
|
|
389 | (3) |
|
Computing a Total with SUM |
|
|
392 | (2) |
|
Calculating a Mean Value with AVG |
|
|
394 | (1) |
|
Finding the Largest Value with MAX |
|
|
395 | (2) |
|
Finding the Smallest Value with MIN |
|
|
397 | (1) |
|
Using More Than One Function |
|
|
398 | (2) |
|
Using Aggregate Functions in Filters |
|
|
400 | (2) |
|
|
|
402 | (7) |
|
|
|
409 | (1) |
|
Problems for You to Solve |
|
|
409 | (4) |
|
|
|
413 | (28) |
|
Topics Covered in This Chapter |
|
|
413 | (1) |
|
|
|
414 | (2) |
|
|
|
416 | (9) |
|
|
|
417 | (4) |
|
Mixing Columns and Expressions |
|
|
421 | (2) |
|
Using Group By in a Subquery in a Where Clause |
|
|
423 | (1) |
|
Simulating a Select Distinct Statement |
|
|
424 | (1) |
|
``Some Restrictions Apply'' |
|
|
425 | (4) |
|
|
|
425 | (2) |
|
|
|
427 | (2) |
|
|
|
429 | (1) |
|
|
|
429 | (10) |
|
|
|
439 | (1) |
|
Problems for You to Solve |
|
|
439 | (2) |
|
|
|
441 | (26) |
|
Topics Covered in This Chapter |
|
|
441 | (1) |
|
A New Meaning of ``Focus Groups'' |
|
|
442 | (4) |
|
When You Filter Makes a Difference |
|
|
446 | (7) |
|
Should You Filter in Where or in Having? |
|
|
446 | (2) |
|
Avoiding the Having Count Trap |
|
|
448 | (5) |
|
|
|
453 | (1) |
|
|
|
454 | (8) |
|
|
|
462 | (1) |
|
Problems for You to Solve |
|
|
462 | (5) |
|
|
|
465 | (2) |
| APPENDICES |
|
467 | (18) |
|
|
|
469 | (8) |
|
B Schema for the Sample Databases |
|
|
477 | (6) |
|
C Recommended Reading References |
|
|
483 | (2) |
| Index |
|
485 | |