* (asterisk), 195
|| (concatenation operator), 138
>= (greater than or equal to), 186
<= (less than or equal to), 186
() (parentheses), 144, 210–211, 216
CASE (conditional expressions), 684
% (percent sign), 195
? (question mark), 195
_ (underscore), 195
2016 SQL Standard, 4
ABS, 142
Access, CASE (conditional expressions), 684
Actian, 74
adding sorting specifications to UNION, 382
aggregate expressions, 445
aggregate functions, 444–446, 798–799
AVG, calculating mean values, 451–452
Bowling League Database, 844–846
COUNT (value expression), 448–449
COUNT(*), 446
counting all the rows, 446–448
finding largest values, 452–454
MIN, finding smallest values, 454–455
Null values, 445
Sales Orders Database, 847–850
Bowling League Database, 463–465
Entertainment Agency Database, 461–462
Sales Orders Database, 460–461
School Scheduling Database, 462–463
School Scheduling Database, 851–852
SUM, computing totals, 450–451
syntax diagrams, 444
using more than one function, 455–457
alias names, assigning to tables, INNER JOIN, 282–284
all rows, deleting with DELETE statement, 605–607
alphabetical order, sorting by, 108
American National Standards Institute (ANSI), 2, 75
analytical databases, 16
finding multiple matches in the same table
Bowling League Database, 663–668
Entertainment Agency Database, 657–659
Sales Orders Database, 653–657
School Scheduling Database, 659–663
sets with multiple AND criteria, 628–629
ANSI (American National Standards Institute), 2, 75
ANSI NCITS-H2, 80
APPROXIMATE NUMERIC, 129
arithmetic operations
Microsoft Access, 893
Microsoft SQL Server, 895
MySQL, 898
Oracle, 902
PostgreSQL, 904
artificial primary keys, 60
assigning correlation names to tables, INNER JOIN, 282–284
asterisks (*), 195
attributes. See columns
AVG, calculating mean values, 451–452
avoiding HAVING COUNT trap, 513–518
base tables, views (relational databases), 23
BETWEEN predicate, 178, 189–192
checking for overlapping ranges, 219–220
BETWEEN…AND, 189
BINARY, 128
blank spaces, 160
BOOLEAN, 129
Bowling League Database
aggregate functions, 463–465, 844–846
CASE (conditional expressions), 702–705
INNER JOIN
looking for matching values, 311–314
subqueries
calculated columns, 40
calculating
row number with ROW_NUMBER, 814–818
totals on combinations using CUBE, 765–770
Call-Level Interface (CLI), 80
Cartesian product, 277–278, 325, 711–712
cascade deletion rule, 63
CASE (conditional expressions), 678
parentheses, 684
reasons for using, 678
Bowling League Database, 702–705
Entertainment Agency Database, 696–698
Sales Orders Database, 693–696
School Scheduling Database, 698–702
searched CASE, solving problems, 688–691
simple CASE, solving problems, 683–687
WHERE clause, 691
CASE expression, syntax diagrams, 679
case sensitivity, 183
string comparison, 197
CAST function
concatenation expressions, 141
CEIL, 142
Chamberlin, Dr. Donald, 72
changing, data types, CAST function, 130–132
CHARACTER, 127
character string literals, 133–134
checking, relationships, INNER JOIN, 291–292
classic set operations versus SQL, 259–262
clauses
embedding SELECT statements, 286
CORRESPONDING clause, 373
HAVING. See HAVING clause
ORDER BY clause. See ORDER BY clause
VALUES clause, INSERT statement, 575–578
WHERE clause. See WHERE clause
CLI (Call-Level Interface), 80
cloud servers, 83
collating sequences, 107
column expressions, subqueries, 402–405, 422–423
syntax diagrams, 276
column restrictions, GROUP BY, 486–488
columns
calculated columns, 40
fine-tuning, 35
mixing with expressions, 481–483
multipart columns, 39
multiple columns, updating, 541–543
multivalued columns, 39
relational databases, 21
requesting all columns with SELECT statement, 101–103
resolving duplicate columns, 50–56
retrieving multiple columns with SELECT statement, 100–101
combining
UNION. See UNION
commercial implementations of SQL, 83
COMMIT, 540
common values, finding with INTERSECT, 262–265
comparing string values, 181–184
comparison predicate, 178, 181
aggregate functions as filters, 457–458
comparing string values, 181–184
equality and inequality, 185–186
less than and greater than, 186–188
composite primary keys, 57
Computer Associates International, Inc., 74
computing totals with SUM, 450–451
concatenation expressions, 138–141
CAST function, 141
syntax diagrams, 138
conditional expressions. See CASE (conditional expressions)
conditions
converting values into data types, CAST function, 130–132
correlation names, assigning to tables (INNER JOIN), 282–284
CORRESPONDING clause, 373
counting all the rows, 446–448
counting values in columns or expressions, 448–449
COUNT (value expression), 446, 448–449
counting all the rows, 446–448
counting
all the rows, COUNT(*), 446–448
values in columns or expressions, 448–449
CROSS JOIN, 713
unlinked tables, 711–712, 715–716
Bowling League Database, 783–784
calculating totals on combinations, 765–770
Sales Orders Database, 784–786
data
fetching from two tables
with JOIN, 370
with UNION, 371
with aggregate functions, 477–478
with GROUP BY. See GROUP BY
mixing columns and expressions, 481–483
inserting
with INSERT statements. See INSERT statement
with SELECT expressions, 581–587
splitting into quintiles, 824–827
unlinked data. See unlinked data
data types
APPROXIMATE NUMERIC, 129
BINARY, 128
BOOLEAN, 129
changing with CAST function, 130–132
CHARACTER, 127
DATETIME, 129
EXACT NUMERIC, 128
extended data types, 130
JOIN eligible data types, 275
for Microsoft Access, 893
for Microsoft SQL Server, 895
MySQL, 897
NATIONAL CHARACTER, 128
Oracle, 901
PostgreSQL, 904
data warehouses, 19
databases
analytical databases, 16
operational databases, 16
relational database model, 16–17
relational databases. See relational databases
Date, C. J., 76
date and time arithmetic expressions, 138, 146
date expressions, 147–148, 156–157
SELECT statement, time expressions, 156
syntax diagrams, 147
DATETIME, 129
DB2, 74
DEFAULT keyword, 576
default pad character, 184
degree of participation, relationships, 66–68
deleting
Bowling League Database, 618–620
Entertainment Agency Database, 614–617
Sales Orders Database, 613–614
School Scheduling Database, 617–618
syntax diagrams, 604
deleting. See also resolving
all rows with DELETE statement, 605–607
duplicate rows with SELECT statement, 50–56
some rows with DELETE statement, 607–611
deletion rule, relationships, 63–64
derived tables, 284
descending order, sorting by, 109
design, database design, 30–31, 34–35
diagrams. See also Appendix A; syntax diagrams
Search Condition, 680
SELECT queries, 106
SELECT statement, 92
problems you can solve with, 256–257
GROUP BY, 485
MAX, 454
MIN, 455
UNION, 389
driver tables, 717
Bowling League Database, 742–743
Entertainment Agency Database, 737–739
Sales Orders Database, 736–737
School Scheduling Database, 739–742
dynamic data, 16
eliminating. See deleting
embedding
INNER JOIN in SELECT statements, 284–286
SELECT statements in OUTER JOINs, 330–333
Entertainment Agency Database
CASE (conditional expressions), 696–698
INNER JOIN
looking for matching values, 309–311
subqueries
Entry SQL, 78
equality, comparison predicate, 185–186
ESCAPE option, LIKE predicate, 198–199
events, relational databases, 20
EXACT NUMERIC, 128
excluding rows with NOT, 201–204, 211–214
executing queries, 112
finding multiple matches in the same table, 646–648
EXP, 142
explicit values, specifying, 132–133
expressing conditions, 225–226
expressions, 126
aggregate expressions, 445
grouping with GROUP BY, 488–490
sample statements, 163
Bowling League Database, 169–171
Entertainment Agency Database, 165–167
Sales Orders Database, 164–165
School Scheduling Database, 167–169
concatenation expressions, 151–152
SELECT expression, 372
SELECT statement
mathematical expressions, 154–156
subqueries, sample statements, 425–430
types of
concatenation expressions, 138–141
date and time arithmetic expressions, 138, 146–150
mathematical expressions, 138, 142–146
UPDATE expressions, subqueries, 548–551
syntax diagrams, 549
extended data types, 130
eXtensible Markup Language (XML), 19
extensions, SQL/92, 79
Federal Information Processing Standard (FIPS), 80
fetching data
from two tables with JOIN, 370
from two tables with UNION, 371
fields. See columns
filter rows, subqueries, 543–546
filtering
deciding between WHERE and HAVING, 510–513
filters
finding
common values, INTERSECT, 262–265
largest values with MAX, 452–454
matching values with INNER JOINs, 293–294
missing values
OUTER JOIN, 349
multiple matches in the same table
partially matched information, OUTER JOIN, 349–350
related rows, INNER JOIN, 293
smallest values with MIN, 454–455
fine-tuning
columns, 35
resolving multipart columns, 40–43
resolving multivalued columns, 43–45
tables, 46
relationships, deletion rule, 63–64
relationships, participation, 64–68
resolving duplicate columns, 50–56
FIPS (Federal Information Processing Standard), 80
FLOOR, 142
foreign keys, relational databases, 22–23
embedding, SELECT statements, 286
INNER JOIN, 277
syntax diagrams, 344
Full SQL, 79
functions
aggregate functions. See aggregate functions
future of SQL (Structured Query Language), 83–84
generating primary key values with INSERT statements, 578–580
greater than or equal to (>=), 186
GROUP BY, 475, 692, 725, 757, 761
finding multiple matches in the same table, 648–652
mixing columns and expressions, 481–483
versus OVER(), 800
Bowling League Database, 496–499
Entertainment Agency Database, 493–494
Sales Orders Database, 491–492
School Scheduling Database, 495–496
SELECT statement, 93
sets with multiple NOT criteria, 638–641
simulating SELECT DISTINCT statements, 484–485
in subqueries in WHERE clauses, 483–484
syntax diagrams, 475
grouped data, filtering, 506–510
grouping
calculating totals on combinations with CUBE, 765–770
creating a union of totals with GROUPING SETS, 771–775
GROUP BY. See GROUP BY
mixing columns and expressions, 481–483
expressions, with GROUP BY, 488–490
totals in hierarchies, ROLLUP, 754–765
variations on techniques, 775–780
GROUPING function, 758
Bowling League Database, 786–787
creating union of totals, 771–775
Entertainment Agency Database, 787–788
HAVING
finding multiple matches in the same table, 648–652
Bowling League Database, 525–526
Entertainment Agency Database, 521–522
Sales Orders Database, 520–521
School Scheduling Database, 522–525
SELECT statement, 93
sets with multiple NOT criteria, 638–641
HAVING COUNT trap, avoiding, 513–518
Hernandez, Mike, 17
hierarchies, totals, ROLLUP, 754–765
history of SQL (Structured Query Language)
commercial implementations, 83
early vendor implementations, 73–74
early vendor implementations, 73–74
IBM DB2
arithmetic operations, 890–908
Identity data type, 579
identifiers
Identity data type, 579
IN, finding multiple matches in the same table, 644–646
IN predicate, 178
INCITS DM32.2, 80
inequality, comparison predicate, 185–186
information
sorting with SELECT statement, 105–107
Ingres, 74
INGRES (Interactive Graphics Retrieval System), 18
Inmon, William H., 19
assigning correlation names to tables, 282–284
FROM clause, 277
embedding
finding
multiple matches in the same table, 642–644
related rows, 293
relationships, checking, 291–292
sample statements, 295
looking for matching values, 306–316
syntax, 276
syntax diagrams, 277
INSERT INTO, 576
generating primary key values, 578–580
Bowling League Database, 596–597
Entertainment Agency Database, 593–595
Sales Orders Database, 589–592
School Scheduling Database, 595–596
SELECT expression, 581
syntax diagrams with VALUES clause, 575
inserting
data
with INSERT statement. See INSERT statement
with SELECT expressions, 581–587
values, with INNER JOINs, 575–578
Interactive Graphics Retrieval System (INGRES), 18
Intermediate SQL, 78
International Organization for Standardization. See ISO (International Organization for Standardization)
problems you can solve with, 249–250
IS NULL predicate, 178
ISO (International Organization for Standardization), 2, 76
determining what is legal to join, 275
embedding within JOINs, 286–291
fetching data from two tables, 370
INNER JOIN. See INNER JOIN
OUTER JOIN. See OUTER JOIN
UNION JOIN, 348
JOIN eligible data types, 275
keys
keywords
DATE, 138
DEFAULT keyword, 576
GROUP BY, 93
HAVING, 93
INSERT INTO, 576
special predicate keywords
TIME, 138
TOP, 111
VALUES, 576
WHERE, 93
largest values, finding with MAX, 452–454
less than or equal to (<=), 186
LIKE predicate, 178
pattern match condition, 194–199
linking
multiple tables, embedding JOINs within JOINs, 286–291
SELECT statements with INTERSECT, 265
character string literals, 133–134
numeric literals, 135
LN, 142
mandatory participation, 64
many-to-many relationships, 61–62
matches, finding multiple matches in the same table
matching values, finding with INNER JOINs, 293–294
mathematical expressions, 138, 142–146
Nulls, 163
parentheses, 144
syntax diagrams, 143
finding largest values, 452–454
mean values, calculating with AVG, 451–452
membership condition, IN predicate, 192–194
arithmetic operations, 893
data types, 893
Microsoft Office Access, CASE (conditional expressions), 684
Microsoft SQL Server
arithmetic operations, 895
data types, 895
Identity data type, 579
MIN, finding smallest values, 454–455
missing values, 161
finding with OUTER JOIN, 349
MOD, 142
multipart columns, 39
multiple columns, updating, 541–543
multiple tables, linking (embedding JOINs within JOINs), 286–291
multivalued columns, 39
MySQL
arithmetic operations, 898
data types, 897
ROLLUP, 765
names, qualifying in ON clause, 279–280
naming conventions
naming expressions (SELECT clause), 152–154
NATIONAL CHARACTER, 128
National Committee for Information Technology Standards (NCITS), 80
National Institute of Standards and Technology (NIST), 80
NCITS (National Committee for Information Technology Standards), 80
nested parenthetical operations, 144
NEXTVAL property, Oracle, 579
NIST (National Institute of Standards and Technology), 80
non-key values, FULL OUTER JOIN, 347–348
NOT
excluding rows, 201–204, 211–214
Bowling League Database, 663–668
Entertainment Agency Database, 657–659
Sales Orders Database, 653–657
School Scheduling Database, 659–663
sets with multiple NOT criteria, 629–630
syntax diagrams, 202
NOT EXISTS, sets with multiple NOT criteria, 637–638
NOT IN, sets with multiple NOT criteria, 635–637
Bowling League Database, 842–843
Entertainment Agency Database, 843–844
Null, 159–162, 199–201, 221–225
aggregate functions, 445
Null condition, syntax diagrams, 199
numeric literals, 135
objects, relational databases, 20
ODBC (Open Database Connectivity), 80
ON clause
search conditions, 278
one-to-many relationships, 61
relational databases, 26
one-to-one relationships, 60–61
Open Database Connectivity (ODBC), 80
operational databases, 16
operations, set operations, 243–244
operators
NOT operator, excluding rows, 211–214
determining result sets, 224
optional participation, 64
determining result sets, 224
Oracle
arithmetic operations, 902
data types, 901
NEXTVAL property, 579
Oracle Corporation, 74
ORDER BY, 106–107, 474, 652–653, 692, 725, 757
sorting SELECT queries, 108–111
UNION, 382
order of precedence, 143
origins of SQL (Structured Query Language), 72–73
orphaned rows, 63
embedding
finding
missing values, 349
partially matched information, 349–350
FULL OUTER JOIN. See FULL OUTER JOIN
grouping data types, 478
Bowling League Database, 359–361
Entertainment Agency Database, 354–355
Sales Orders Database, 351–353
School Scheduling Database, 356–359
sets with multiple NOT criteria, 632–635
versus GROUP BY, 800
predicates
overlapping ranges, checking for, 219–221
CASE expression, 684
mathematical expressions, 144
partially matched information, finding with OUTER JOIN, 349–350
participation, relationships, 64–68
pattern match condition, 194–199
syntax diagrams, 195
pattern strings, samples, 195–196
percent sign (%), 195
arithmetic operations, 904
data types, 904
POWER, 142
BETWEEN … AND, 189
BETWEEN, 178
comparison, 178
comparison predicate, aggregate functions as filters, 457–458
IN, 178
IS NULL, 178
LIKE, 178
pattern match condition, 194–199
primary key values, generating with INSERT statements, 578–580
primary keys, 20
primary tables, one-to-one relationships, 25
prioritizing search conditions, order of precedence, 215–217
problems, solving
qualifying names, ON clause, 279–280
quantified predicates, (SOME, ANY, ALL), 417–420
QUEL (Query Language), 74
queries
executing, 112
RDBMS (relational database management system), 24
SELECT queries. See SELECT query
Query Language (QUEL), 74
query optimizers, 218
question mark (?), 195
quintiles, splitting, data, 824–827
quotes, single quote, 133
ranges, overlapping ranges (checking for), 219–221
ranking data, with RANK(), 818–824
RDBMS (relational database management system), 17–19, 74
REAL, 146
reasons for learning SQL (Structured Query Language), 84
Recipes Database
INNER JOIN
looking for matching values, 314–315
subqueries
records. See rows
refining searches, 176
related rows, finding with INNER JOINs, 293
relational database management system (RDBMS), 17–19, 74
relational database model, 16–17
relational databases
columns, 21
relations, 19
relationships, 25
one-to-many, 26
Relational Software, Inc., 74
Relational Technology, Inc., 74
relations. See tables
relationships
checking with INNER JOIN, 291–292
many-to-many relationships, 61–62
one-to-many relationships, 61
one-to-one relationships, 60–61
relational databases, 25
one-to-many, 26
requests
translating into SQL, SELECT statement, 95–99
writing with UNION, 372
combining complex SELECT statements, 375–379
using simple SELECT statements, 372–375
resolving. See also deleting
restrict deletion rule, 63
restrictions, column restrictions (GROUP BY), 486–488
result sets
determining with OR, 224
retrieving multiple columns, with SELECT statement, 100–101
ROLLBACK, 540
MySQL, 765
Sales Orders Database, 781–782
School Scheduling Database, 782–783
totals in hierarchies, 754–765
row numbers, calculating with ROW_NUMBER, 814–818
row value constructors, 401
ROW_NUMBER(), 814–818, 827–828, 829
Entertainment Agency Database, 835–837
rows
counting with COUNT(*), 446–448
deleting all rows with DELETE statement, 605–607
deleting some rows with DELETE statement, 607–611
eliminating duplicates with SELECT statement, 103–105
excluding, with NOT, 201–204, 211–214
filter rows, subqueries, 543–546
related rows, finding with INNER JOIN, 293
selected rows, updating, 631–633
ROWS (or RANGE), 811–814, 827–828
SAA (Systems Application Architecture), 80
Sales Orders Database
aggregate functions, 460–461, 847–850
CASE (conditional expressions), 693–696
INNER JOIN
looking for matching values, 306–309
subqueries
sample statements
Bowling League Database, 463–465
Entertainment Agency Database, 461–462
Sales Orders Database, 460–461
School Scheduling Database, 462–463
Bowling League Database, 663–668
Entertainment Agency Database, 657–659
Sales Orders Database, 653–657
School Scheduling Database, 659–663
CASE (conditional expressions), 692–693
Bowling League Database, 702–705
Entertainment Agency Database, 696–698
Sales Orders Database, 693–696
School Scheduling Database, 698–702
Bowling League Database, 618–620
Entertainment Agency Database, 614–617
Sales Orders Database, 613–614
School Scheduling Database, 617–618
Bowling League Database, 169–171
Entertainment Agency Database, 165–167
Sales Orders Database, 164–165
School Scheduling Database, 167–169
Bowling League Database, 496–499
Entertainment Agency Database, 493–494
Sales Orders Database, 491–492
School Scheduling Database, 495–496
Bowling League Database, 525–526
Entertainment Agency Database, 521–522
Sales Orders Database, 520–521
School Scheduling Database, 522–525
INNER JOIN, 295
looking for matching values, 306–316
Bowling League Database, 596–597
Entertainment Agency Database, 593–595
Sales Orders Database, 589–592
School Scheduling Database, 595–596
Bowling League Database, 663–668
Entertainment Agency Database, 657–659
Sales Orders Database, 653–657
School Scheduling Database, 659–663
Bowling League Database, 359–361
Entertainment Agency Database, 354–355
Sales Orders Database, 351–353
School Scheduling Database, 356–359
Bowling League Database, 231–232
Entertainment Agency Database, 228–229
Sales Orders Database, 227–228
School Scheduling Database, 230–231
Bowling League Database, 119–120
Entertainment Agency Database, 116–117
Sales Orders Database, 114–115
School Scheduling Database, 117–118
Bowling League Database, 428–429, 434–435
Entertainment Agency Database, 426–427, 432–433
Recipes Database, 429–430, 435–437
Sales Orders Database, 425–426, 430–431
School Scheduling Database, 427–428, 433–434
Bowling League Database, 392–394
Entertainment Agency Database, 389–390
Sales Orders Database, 385–389
School Scheduling Database, 390–392
unlinked data
Bowling League Database, 565–568
Entertainment Agency Database, 558–562
Sales Orders Database, 554–557
School Scheduling Database, 562–565
RANK(), DENSE_RANK, and PERCENT_RANK, 838–841
samples, defined pattern strings, 195–196
saved queries, RDBMS (relational database management system), 24
saving SELECT statement, 111–112
schema for sample databases. See Appendix B
School Scheduling Database
aggregate functions, 462–463, 851–852
CASE (conditional expressions), 698–702
INNER JOIN
looking for matching values, 311
subqueries
search conditions, 177
Bowling League Database, 231–232
Entertainment Agency Database, 228–229
Sales Orders Database, 227–228
School Scheduling Database, 230–231
searched CASE, solving problems, 688–691
searching, for unknown values, 199–201
secondary tables, one-to-one relationships, 25
SELECT clause, expressions, 150–151
concatenation expressions, 151–152
SELECT DISTINCT statements, simulating, 484–485
SELECT expression, 372
SELECT queries, 106
diagrams, 106
FROM clause, 331
complex SELECT statements, combining, 375–379
data versus information, 93–95
date expressions, time expressions, 156
diagrams, 92
embedding
expressions
mathematical expressions, 154–156
GROUP BY, syntax diagrams, 475
requesting all columns, 101–103
retrieving multiple columns, 100–101
rows, eliminating duplicates, 103–105
Bowling League Database, 119–120
Entertainment Agency Database, 116–117
Sales Orders Database, 114–115
School Scheduling Database, 117–118
simple SELECT statements
syntax diagrams, 403
writing requests with UNION, 372–375
translating requests into SQL, 95–99
selected rows, updating, 631–633
SEQUEL (Structured English Query Language), 72
SEQUEL-XRM, 72
set membership, IN predicate, 411–417
classic set operations versus SQL
problems you can solve with, 256–257
problems you can solve with, 249–250
union, 243
combining result sets, 259–261
problems you can solve with, 261–262
set theory
AND, multiple AND criteria, 628–629
combining
finding multiple matches in the same table
including some criteria but excluding others, 630–631
NOT
multiple NOT criteria, 629–630
shortcuts, requesting all columns with SELECT statement, 101–103
simple CASE, solving problems, 683–687
simple primary keys, 57
simple SELECT statements, syntax diagrams, 403
simple UPDATE expression, 537–538
simple WHERE clause, deleting some rows, 607
simulating SELECT DISTINCT statements, GROUP BY, 484–485
single quote, 133
smallest values, finding, with MIN, 454–455
solving problems
some rows, deleting with DELETE statement, 607–611
sorting
by alphabetical order, 108
information
ORDER BY clause, SELECT queries, 108–111
special predicate keywords, subqueries
specifying, explicit values, 132–133
Specifying Queries As Relational Expressions (SQUARE), 73
splitting data into quintiles, 824–827
SQL (Structured Query Language)
commercial implementations, 83
history of SQL (Structured Query Language)
early vendor implementations, 73–74
reasons for learning, 84
set operations
standards. See standards
SQL Standard, structure of, 81–82
SQL/86, 76
SQL/Data System (SQL/DS), 74
SQL/DS (SQL/Data System), 74
SQRT, 142
SQUARE (Specifying Queries As Relational Expressions), 73
standards
FIPS (Federal Information Processing Standard), 80
history of SQL (Structured Query Language), 75–76
ODBC (Open Database Connectivity), 80
SAA (Systems Application Architecture), 80
SQL Standard, structure of, 81–82
X/OPEN, 79
START TRANSACTION, 540
static data, 16
Stonebraker, Michael, 74
string comparison, case sensitivity, 197
string values, comparing, 181–184
structure of
Structured English Query Language (SEQUEL), 72
as column expressions, 402–405, 422–423
deleting some rows, DELETE statement, 609–611
Bowling League Database, 428–429, 434–435
Entertainment Agency Database, 426–427, 432–433
Recipes Database, 429–430, 435–437
Sales Orders Database, 425–426, 430–431
School Scheduling Database, 427–428, 433–434
special predicate keywords
in WHERE clauses, GROUP BY, 483–484
subtotal combinations, calculating with CUBE, 765–770
SUM, computing totals, 450–451
syntax
CASE (conditional expressions), 678–682
INNER JOIN, 276
subqueries as column expressions, 402–405
subqueries as filters, 408–411
syntax diagrams
aggregate functions, 444
CASE expression, 679
column references, 276
comparison condition, 181
concatenation expressions, 138
date and time literals, 136
date expressions, 147
DELETE statement, 604
FULL OUTER JOIN, 344
INSERT statement with SELECT expressions, 581
INSERT statement with VALUES clause, 575
mathematical expressions, 143
naming expressions, 153
NOT operator, 202
Null condition, 199
numeric literals, 135
pattern match condition, 195
query using INNER JOIN on two tables, 277
range condition, 189
search conditions, 205
SELECT statement that includes value expression, 159
SELECT statement with GROUP BY clause, 475
SELECT statement with WHERE clause, 177
simple SELECT statements, 403
time expressions, 149
UNION JOIN, 348
UNION statement, 370
using UNION to combine two simple SELECT statements, 372
Value Expression, 679
table references, 345
tables
assigning correlation names to, INNER JOIN, 282–284
derived tables, 284
driver tables, 717
Bowling League Database, 742–743
Entertainment Agency Database, 737–739
Sales Orders Database, 736–737
School Scheduling Database, 739–742
fine-tuning, 46
relationships, deletion rule, 63–64
relationships, participation, 64–68
resolving duplicate columns, 50–56
linking, embedding JOINs within JOINs, 286–291
unlinked tables, 713
techniques for grouping, variations on, 775–780
TIME, 136
SELECT statement, 156
syntax diagrams, 149
TOP, 111
totals
calculating totals on combinations, using CUBE, 765–770
creating a union of totals, with GROUPING SETS, 771–775
in hierarchies, ROLLUP, 754–765
translating requests into SQL, SELECT statement, 95–99
translation statements, 108
tuple. See rows
type of participation, relationships, 64–68
types of data, expressions, 127–130
types of expressions
concatenation expressions, 138–141
date and time arithmetic expressions, 138, 146
mathematical expressions, 138, 142–146
underscore (_), 195
combining three tables, 380
DISTINCT, 389
fetching data from two tables, 371
Bowling League Database, 392–394
Entertainment Agency Database, 389–390
Sales Orders Database, 385–389
School Scheduling Database, 390–392
syntax diagrams, 370
combining two simple SELECT statements, 372
writing requests, 372
combining complex SELECT statements, 375–379
using simple SELECT statements, 372–375
union, 243
problems you can solve with, 261–262
result sets, combining, 259–261
UNION ALL, 371
UNION JOIN, 348
union of totals, creating with GROUPING SETS, 771–775
driver tables, 717
sample statements
unlinked tables, 713
Bowling League Database, 734–735
Entertainment Agency Database, 728–731
Sales Orders Database, 726–728
School Scheduling Database, 731–734
UPDATE expressions
simple UPDATE expression, 537–538
Bowling League Database, 565–568
Entertainment Agency Database, 558–562
Sales Orders Database, 554–557
School Scheduling Database, 562–565
subqueries in filter rows, 543–546
updating
updating
USING syntax, OUTER JOIN, 329
syntax diagram, 679
values
converting into data types, CAST function, 130–132
finding largest values, with MAX, 452–454
inserting with INSERT statements, 575–578
matching values, finding with INNER JOIN, 293–294
mean values, calculating with AVG, 451–452
missing values, 161
finding with OUTER JOIN, 349
non-key values, FULL OUTER JOIN, 347–348
smallest values, finding with MIN, 454–455
unknown values, 161
VALUES clause
syntax diagrams, INSERT statement, 575
VALUES keyword, 576
verifying you’re updating the correct rows, 632–633
views, relational databases, 23–24
VM/CMS operating system, 74
CASE (conditional expressions), 691
comparison predicate, 181
comparing string values, 181–184
equality and inequality, 185–186
less than and greater than, 186–188
deleting, some rows, 607
IS NULL, unknown values, 199–201
LIKE predicate, pattern match condition, 194–199
IN predicate, membership condition, 192–194
SELECT statement, 93
subqueries
WIDTH_BUCKET, 142
calculating row number, 814–818
OVER()
ranking data with RANK(), 818–824
Sales Orders Database, 838–839
RANK(), DENSE_RANK, and PERCENT_RANK, 838–841
School Scheduling Database, 840–841
splitting data into quintiles with NTILE(), 824–827
WITH RECURSIVE, 717
Wong, Eugene, 74
writing requests with UNION, 372
combining complex SELECT statements, 375–379
using simple SELECT statements, 372–375
X3, 75
XML (eXtensible Markup Language), 19
X/OPEN, 79
zero, 160
zero-length string, 160