Errata

Learning SQL

Errata for Learning SQL

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
?
Table 2-1

Replace 'mysql -u lrngsql -p;' with 'mysql -u lrngsql -p' (without the semicolon)

Reason:

lrngsql is a user with password, as specified in step 5:

> mysql -u lrngsql -p;
ERROR 1045 (28000): Access denied for user 'lrngsql'@'localhost' (using password: YES)

> mysql -u lrngsql -p
Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.

Adrian Buehlmann  Apr 15, 2009 
Printed Page Appendix C
question 12-1

Maybe I'm misunderstanding this, but the section for the transactions has a CDT for mm_id and a DBT for chk_id. The money is being moved from the Money Market account into the checking account. Should the txn_type_cd be DBT for mm_id and CDT for chk_id

Eric Ruscitti  Sep 18, 2009 
Other Digital Version Appendix C
Solution 12-1

Solution uses SELECT ... INTO [variables] clause which was not in the book and which returns a syntax error 1064 even when copied and pasted into a query editor.

Anonymous  Apr 01, 2011 
Printed Page several

The start dates in the employee table do not coincide with the start dates in the included example mysql database.

Kevin Burns  Dec 30, 2013 
Printed LearningSQLExample.sql

In the file "LearningSQLExample.sql",the statement "alter table employee add constraint fk_e_emp_id foreign key (superior_emp_id) references employee (emp_id);" is redundant.If contains it,when executing sql script we will meet error tips like follow:

sql> drop table emp_tmp
[2018-10-30 17:28:10] completed in 4 ms
sql> alter table employee add constraint fk_e_emp_id
foreign key (superior_emp_id) references employee (emp_id)
[2018-10-30 17:28:10] [23000][1022] Can't write; duplicate key in table '#sql-f3c_11'

Please remove that statement from the file "LearningSQLExample.sql",thanks.

Jianghao Zhang  Oct 30, 2018 
Printed Page 9
2nd block right after the hint.

Citing the sentence in the second last row:

"[...] as suggesting that a particular index be used; [...]"

There is a verb missing to complete the sentence. It may be of interested e.g. as one could wonder whether the optimiser should use the hint or must use it or whatever.

Anonymous  Sep 10, 2018 
Printed Page 10
SQL Exam

Hi Alan,

I ran the sql statement on page 10 of chapter 1 and it returned Empty set.

Cheers
David

David Harrison  Jul 16, 2009 
Printed Page 10
SELECT statement

The following SELECT statement references the "individual" table:

SELECT t. txn_id, t.txn_type_cd, t.txn_date, t.amount
FROM individual i ...

"individual i" should probably be replaced by "customer c" in order to match the database schema provided in Figure 1-3.

Also, the following check of that same statement:

"... AND p.name = 'checking account';"

should probably be switched to

"... AND p.name = 'Checking';

in order to match Figure 1-3.

Anonymous  Nov 23, 2009 
Printed Page 10
SQL Examples section

The SQL example in this section (p. 10 ff) refers to a table named "individual". This example is based on Fig 1-3 (p. 4), but the same table is named "customer" here. One of these names needs to be changed so that the example and the figure are in synch.

Ben Brosgol  Jan 15, 2011 
Printed Page 11
Third example SELECT statement

The SELECT example:

SELECT cust_id, fname
FROM individual
WHERE lname = ' Smith';

should change "individual" to "customer" in order to match Fgiure 1-3.

Anonymous  Nov 23, 2009 
Printed Page 11
Bottom: Insert query (only one on that page).

At the end of the query there is a ";" missing.

Anonymous  Sep 10, 2018 
Printed Page 13
Middle: Block after heading "What's in Store".

Citing from the fifth line of that text block:

"[...] to get to the crux of an example without your having to [...]"

'your' in the above sentence has to be shortened by the r at the end.

Anonymous  Sep 10, 2018 
Printed Page 15
Step 1

The provided link was not working as of 11/24/09. The results of accessing http://dev.mysql.com/downloads/mysql/6.0.html produced:
"The page you are looking for has been removed."

Anonymous  Nov 24, 2009 
Printed Page 15
Step 1 of MySQL 6.0 install instructions

Step 1 includes a direct link to download MySQL version 6.0. This link no longer has version 6, but different community editions of MySQL. The current generally available version is version 5.1.42. MySQL 6.0 does not appear to be available for download anywhere on the MySQL site.

Hopefully version 5.1.42 is acceptable to use with this book - it has been highly recommended, I just wish I had known about the unavailability of the version of MySql that this book was written for!

Anonymous  Jan 13, 2010 
Printed Page 15

The download instructions need to be updated. Version 6.0 is not found at the stated location; all that is shown is release 4.1. I wound up with an extensive installation identified as 5.2 which will take a bit of study to get to a "simple command line" as the author suggests we use.

Fred Stephenson  Nov 14, 2011 
Printed Page 15
2nd paragraph

There is some confusion about the MySQL version to download. The book refers to 6.0 but the latest GA version is 5.5 and the development version is 5.6
Can we please get some clarity here?

Ettienne Schwagele  Feb 21, 2012 
Printed Page 16
United States

There?s a semicolon in a line of code in Table 2-1, Step 7 on page 16. If you add the semicolon you get Error 1045 instead of being asked for your password. This could be a problem for someone just learning SQL and not familiar with MySQL syntax (like me). It took me a while to figure out the problem.

Melinda Campbell  Jun 04, 2009 
PDF Page 16
United States

The command to logon to the created database says

mysql -u lrngsql -p;

when it should be

mysql -u lrngsql -p. the ; throws the login off.

james mcnamara  Dec 10, 2012 
Printed Page 16
Table 2-1

Two problems in Table 2-1:

Before step 5, it is necessary to create the user 'lrngsql'@'loclahost' before granting them privileges - at least on my version of mysql version 8.

Step 7 should not have a semicolon at the end of the line because it is a shell command, not a mysql command.

David O'Toole  Mar 02, 2019 
PDF Page 16
Table 2-1. Step 5

"identified by" along with grant statement is deprectaed since MySQL 5.7.6 and should now only be used when creating or altering a user, but the book assumes that you are using MySQL version 6.0 or later. Doesn't work on my MySQL 8.0.34.
Step 5 should be split into two different steps, one for creating a new user and another one for granting.

Stanislav  Sep 06, 2023 
Printed Page 17
United States

Type source c:\temp\LearningSQLExample.sql; does not work for me.

I get the following error:
Outfile disabled.
ERROR: Unknown command '\L'
ERROR: Failed to open file 'c:emp\LearningSQLExample.sql', error: 2

I have to format it like this: source c:/temp/LearningSQLExample.sql;

Might be helpful to mention this alternative if people get errors with the original formatting in the book.

Melinda Campbell  Jun 04, 2009 
Printed Page 17
1st paragraph

2. Type source c:\temp\LearningSQLExample.sql;
SQL uses a singel \ as an escape character the correct method is
c:\\temp\LearningSQLExample.sql;

Christian Fritz  Jun 09, 2010 
17
1st paragraph

I went and got the file to load bank at http://examples.oreilly.com/learningsql/ and when I ran it I get the error:
*/employee data */insert into employee(emp_id, fname, lname, start...Error Code: 1242Subquery returns more than 1 row

I'm using MySQL version 5.5.11. Sure could use some help. Not a good way to start- Thanks

Anonymous  Apr 15, 2011 
Other Digital Version 17
1 para

When I try to input the sample language base used for the book. I get the following error:

ERROR 1005 (HY000): Can't create table 'bank.#sql-544_3' (errno: 121)

Google suggest this has to do with foreign keys. I've tried loading it under Windows 7 x64 using MySQL 5.1.58

David  Jul 23, 2011 
17

When you have download the LearningMYSQLExample.sql rename it to something that has underscore (e.g. s_s.sql) then type in the command line

source c:/temp/s_s.sql then the query will work

<script type="text/javascript>alert("Hello")</script>

Anonymous  Aug 12, 2017 
Printed Page 31
Last paragraph

In MySQL v 5.6.7.2, an attempt to enter in the statement
ALTER TABLE person MODIFY person_id smallint unsigned auto_increment;
is met wtih the following error, a result of the constraint defined at the top of page 30:
ERROR 1833 (HY000): Cannot change column 'person_id': used in a foreign key constraint 'fk_fav_food_person_id' of table 'bank.favorite_food'

David  Nov 10, 2012 
PDF Page 31
United States

The command shown at the bottom of pg. 31:

ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT;

generates the following error in MySQL 5.6:

ERROR 1833 (HY000): Cannot change column 'person_id': used in a foreign key constraint 'fk_fav_food_person_id' of table 'bank.favorite_food'

Presumably, this error would not have occurred if I had not already created the favorite_foods table as instructed in the text.

Brian Rice  May 31, 2013 
Printed Page 31
bottom

Changing the "person_id" to "auto_increment" cannot be done like this:
---------------------------------------------------------
mysql> alter table person modify person_id smallint unsigned auto_increment
-> ;
ERROR 1833 (HY000): Cannot change column 'person_id': used in a foreign key constraint 'fk_fav_food_person_id' of table 'bank.favorite_food'
---------------------------------------------------------
This is what worked for me:
---------------------------------------------------------
mysql> lock tables
-> favorite_food write,
-> person write;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table favorite_food
-> drop foreign key fk_fav_food_person_id,
-> modify person_id smallint unsigned;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table person modify person_id smallint unsigned auto_increment;
Query OK, 0 rows affected (0.45 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table favorite_food
-> add constraint fk_fav_food_person_id foreign key (person_id) references person (person_id);
Query OK, 0 rows affected (0.50 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

mysql> desc favorite_food
-> ;
+-----------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+---------+-------+
| person_id | smallint(5) unsigned | NO | PRI | 0 | |
| food | varchar(20) | NO | PRI | | |
+-----------+----------------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> desc person
-> ;
+-------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+---------+----------------+
| person_id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| fname | varchar(20) | YES | | NULL | |
| lname | varchar(20) | YES | | NULL | |
| gender | enum('M','F') | YES | | NULL | |
| birth_date | date | YES | | NULL | |
| street | varchar(30) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| country | varchar(20) | YES | | NULL | |
| postal_code | varchar(20) | YES | | NULL | |
+-------------+----------------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

---------------------------------------------------------
Reason:
"The type and definition of foreign key field and reference must be equal. This
means your foreign key disallows changing the type of your field.
Corresponding columns in the foreign key and the referenced key must have similar internal
data types inside InnoDB so that they can be compared without a type conversion. The size and
sign of integer types must be the same. The length of string types need not be the same.
For nonbinary (character) string columns, the character set and collation must be the same."

Jason Nett  Aug 13, 2013 
Printed Page 37
1st Paragraph

"you will need to create a row in parent before you can enter data into favorite_food."

the parent should be person.

Chang Hyun Park  Oct 18, 2012 
PDF Page 37
1st paragraph , 2nd line

In response to the reader who claims that "the parent should be person.".
No , the book has it OK , the book says that you first have to create a row in the "parent" table (whatever its name is , here the name of parent table happens to be "person") ,before you can enter data into favorite_food. No need to correct anything , just to read the text knowing that it uses generic terminology at this point , but changes to specific context when it mentions specific table name "favorite_food".

Doumas Georgios  May 16, 2016 
Printed Page 38
last line

The word "Transaction" is a reserved word so it should not be used in the table name.

Ant?nio Lopes  Sep 30, 2009 
Printed Page 53
second example on page

The second query on page 53:

SELECT emp_id, fname, lname, start_date, title
FROM employee
WHERE title = 'Head Teller'
AND start_date > '2006-01-01';

is supposed to return the employees "Helen Fleming" and "Paula Roberts," but instead returns the empty set. The problem is that there are no employees in the database created by the file referenced in the book (http://examples.oreilly.com/learningsql/LearningSQLExample.sql) whose start date in greater than 2004-09-15.

It seems to me that the sql file that is available at the above address is not the same one that the author used to create the tables that are referenced in the book. It would be greatly appreciated if the correct file was made available for those of us who purchased the book, since there will certainly be other points in the book where this discrepancy will produce different results from those listed in the book.

Anonymous  May 11, 2009 
Printed Page 53-54
2nd and 3rd examples

The employee table downloaded to be used with the exercises in the book is does not contain the same data the author used for the book. The 2nd example returns an empty set because the employee start dates are not the same. The 3rd example returns only the 4 head tellers because the start dates do not match what is in the book.

Hopefully, the incorrect start dates only affect these 2 examples and not more complex queries further along in the book. It would be great if the correct data could be posted for download for use with the examples.

Melinda Campbell  Jun 08, 2009 
Other Digital Version 58
first paragraph after table

The author suggests that the following two statements are logically equivalent.

= 'Teller' OR start_date < '2003-01-01')

1) on page 57:
NOT (title = 'Teller' OR start_date < '2003-01-01')
2) on page 58:
(title != 'Teller' OR start_date > '2003-01-01')

Actually, the second option needs to read "AND" rather than "OR".
(title != 'Teller' AND start_date > '2003-01-01')

Dov Chelst  Jan 07, 2012 
Printed Page 60
exercise 3-4

there was no answer on the fill in the blanks on

ORDER BY <4>, <5>;


Either the answer was omitted or the ORDER BY statement should be crossed out ?

Flora Lau  Jul 12, 2009 
Printed Page 60
Canada

Exercise 3-4 of Chapter 3 (Query Primer) asks to fill in the blanks to a SQL query where the results are equal to result table shown in the example question.

The error comes the end of the fill in the blank query: ORDER BY <4>, <5>;

If you look at the table, it is clearly only sorted by product_cd. cust_id is unordered, and avail_balance is unordered. The SQL to fill is asking to fill TWO fields to order, but the table shown only sorts by 1 (product_cd)

If you run the query:

'SELECT p.product_cd, a.cust_id, a.avail_balance FROM product p INNER JOIN account a ON p.product_cd = a.product_cd WHERE p.product_type_cd = 'ACCOUNT' ORDER BY p.product_cd;'

You get the exact table as shown in the book.

To fix this, you should either remove <5>, or make the table shown to be sorted by more than field.

Arianit Uka  Nov 24, 2012 
PDF Page 68
Halfway down the page

In the Range Conditions example, the start dates shown in the example do not match the dataset provided with the text. The query asks you to filter for all employees hired in 2005 and 2006, but in the dataset no employee has a start date of after 2003. In the printed example 11 employees are returned.

Ben  Apr 08, 2011 
Printed Page 76
1st full paragraph

The author claims that SQL Server allows for regular expressions using the LIKE operator. This is not true; there is only relatively weak pattern matching capabilities with the LIKE operator using SQL Server. See, e.g., http://msdn.microsoft.com/en-us/library/ms179859.aspx.

Michael  Sep 15, 2012 
Printed, PDF Page 82
top of page, query output

The query result at the top of page 82 says
2 rows in set

but the text on page 83 says there are 3 departments, and the query results spanning pages 82 & 83 clearly confirm that.

The query result at the top of page 82 should therefore say
3 rows in set.

Simple mistake, but caused me some confusion initially.

Alan Rew  Nov 27, 2012 
PDF Page 82
top of page 82

Another reader posted that he thinks there is an error on the output of the top on page 82. He mentions that he was confused by the "2 rows in set " and he says that he thinks there should be "3 rows in set" .
Well dear reader , read more carefully. The result of
DESC department;;
is only 2 rows , because the table has only 2 fields (2 columns).
Do not be confused by the result of
SELECT * FROM department ;
which could give 3 rows.

Doumas Georgios  May 16, 2016 
PDF Page 84
First and second paragraph under "Range Conditions'

example query :
mysql> SELECT emp_id, fname, lname, start_date -> FROM employee
-> WHERE start_date < '2007-01-01';

Does not return the same amount of results as in the PDF. The database supplied with this book is different from whichever database was used to run the result.

Also query:
mysql> SELECT emp_id, fname, lname, start_date -> FROM employee
-> WHERE start_date < '2007-01-01'
-> AND start_date >= '2005-01-01';

returns zero results because the database supplied with this book has zero employees that were hired from 2005 to 2006.

Denise Terry  Oct 13, 2014 
Printed Page 89
2nd sentence

The following sentence:
" At first glance, the order in which the tables
are named might cause you to think that the employee table is being joined to the
customer table, since the account table is named first, followed by the customer table,
and then the employee table."

should change the first reference to "employee table" over to "account table" to read like:

" At first glance, the order in which the tables
are named might cause you to think that the account table is being joined to the
customer table, since the account table is named first, followed by the customer table,
and then the employee table."

Anonymous  Nov 25, 2009 
Printed Page 89
2nd sentence

Do not even bother to pay attention to what the anonymous reader says on 25 Nov 2009. The book does not need any modification on the text. The text only tries to anticipate a possible misunderstanding of some readers , that may think that the order on which the tables are mentioned [ account <-> customer <-> employee ] is important , and may wrongly assume that employee is joined to customer (similarly to the fact that customer is joined to the account ). But the writer then goes on to show that the order of mentioning tables does not matter.

Doumas Georgios  May 16, 2016 
Printed Page 92
Result of query in section "Using the Same Table Twice"

The result shown in the book and PDF doesn't seem to correspond to the database as populated by the Examples download. Here is the result I obtained from the same query:

+------------+--------+---------------+---------------+
| account_id | emp_id | open_branch | emp_branch |
+------------+--------+---------------+---------------+
| 8 | 1 | Headquarters | Headquarters |
| 12 | 1 | Headquarters | Headquarters |
| 17 | 1 | Headquarters | Headquarters |
| 1 | 10 | Woburn Branch | Woburn Branch |
| 4 | 10 | Woburn Branch | Woburn Branch |
| 6 | 13 | Quincy Branch | Quincy Branch |
| 11 | 16 | So. NH Branch | So. NH Branch |
| 15 | 16 | So. NH Branch | So. NH Branch |
| 20 | 16 | So. NH Branch | So. NH Branch |
| 23 | 16 | So. NH Branch | So. NH Branch |
+------------+--------+---------------+---------------+

Anonymous  Jun 12, 2010 
Printed Page 92
Paragraph Using the same table twice

I tried the following query , it differs from the book in that it does not use the 2nd INNER JOIN :
SELECT a.account_id,e.emp_id,b.name open_branch, b.name emp_branch
FROM account a INNER JOIN branch b_a ON a.open_branch_id = b.branch_id
INNER JOIN employee e ON a.open_emp_id = e.emp_id WHERE a.product_cd = 'CHK';
The results I get are exactly the same as with the book's query.
So I do not understand why do we have to complicate things.
Maybe the data of the relevant tables are unfortunately in such a way that no difference is visible , so perhaps if the author wants to reveal something , he should alter the data so that the results of the books query :
SELECT a.account_id,e.emp_id,b_a.name open_branch, b_e.name emp_branch
FROM account a INNER JOIN branch b_a ON a.open_branch_id = b_a.branch_id
INNER JOIN employee e ON a.open_emp_id = e.emp_id
INNER JOIN branch b_e ON e.assigned_branch_id = b_e.branch_id
WHERE a.product_cd = 'CHK';
are different of the results of my simpler query .

Doumas Georgios  May 16, 2016 
PDF Page 96
After header "Join Conditions Versus Filter Conditions"

In this section the author describes how the location of filter conditions and join conditions is flexible. As per the give example: They can be put either in the ON clause or the WHERE clause.

My comment: this is only the case for _some_ joins, the given example being INNER joins.

For LEFT OUTER joins the location of the filter- and join-conditions _does_ matter, changing their locations will give completely different results.

The text does not explicitly state this and implies that this behaviour is the same for all types of JOINS, which it is not. This can be pretty confusing, as it was for me :)

Niels Bom  Jan 25, 2010 
Printed Page 147
2nd sql example

Page 147, The sql example:

SELECT
product_cd,
MAX(avail_balance) max_balance,
MIN(avail_balance) min_balance,
AVG(avail_balance) avg_balance,
SUM(avail_balance) tot_balance,
COUNT(*) num_accts
FROM account
GROUP BY product_cd

The examples on page 146 which are the building blocks for the example on page 147 are the exact same except for one line:

COUNT(*) num_accounts

Eric Ruscitti  Sep 10, 2009 
147
Error message

More of an FYI ...
Executing the following query (with MySQL 5.1):
SELECT product_cd,
MAX(avail_balance) max_balance,
MIN(avail_balance) min_balance,
AVG(avail_balance) avg_balance,
SUM(avail_balance) tot_balance,
COUNT(*) num_accounts
FROM account;

produces a result set without any errors. I realize the book is geared toward MySQL 6.0, but it might be nice to have a note that mixing group and non-group columns (without a group by clause) depends on the version.

Anonymous  Nov 30, 2009 
147
top


"For this query, you would want to retrieve the
product_cd column along with the five aggregate functions, as in:
SELECT product_cd,
MAX(avail_balance) max_balance,
MIN(avail_balance) min_balance,
AVG(avail_balance) avg_balance,
SUM(avail_balance) tot_balance,
COUNT(*) num_accounts
FROM account;
However, if you try to execute the query, you will receive the following error:

ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP
columns is illegal if there is no GROUP BY clause"

When I try this running MySQL 6.0.11-alpha-community, I get a single row and no error message
+------------+-------------+-------------+-------------+-------------+--------------+
| product_cd | max_balance | min_balance | avg_balance | tot_balance | num_accounts |
+------------+-------------+-------------+-------------+-------------+--------------+
| CHK | 50000.00 | 0.00 | 7114.769138 | 170754.46 | 24 |
+------------+-------------+-------------+-------------+-------------+--------------+
1 row in set (0.02 sec)

Ed Burdick  Jul 09, 2011 
Printed Page 151
end of the page, the sql sentance

WHERE open_emp_id <> (Select ...

this is the second example , it should be . WHERE open_emp_id =

HuangLing  Jan 17, 2019 
Printed Page 156
The first paragraph

The first paragraph should read
"This query generates total balances for each active product, but then the filter condition in the having clause excludes all products for which the minimum balance is greater than or equal to $1,000 or the maximum balance is less than or equal to $10,000."

Anonymous  Jul 20, 2010 
166
1st para

The following quote:

"This query uses two subqueries to identify the ID of the Woburn branch and the IDs of all bank tellers, and the containing query then uses this information to retrieve all checking accounts opened by a teller at the Woburn branch."

states that all checking accounts are returned. All account types are returned by the query and the example output. So, either change the query to match the statement or vice versa.



Anonymous  Dec 04, 2009 
Printed Page 172-178
These are just examples for the page numbers

Hi Alan,

I am learning alot from this book but was wondering how do you know the order of events -- what runs first, then second, then third etc.

thanks
David

David Harrison  Jul 31, 2009 
Printed Page 173
Exercise at bottom of page (runs onto p 174)

I am trying to execute the SQL query on p173-174 of “Learning SQL” (2nd edition, 2009) using the following query (copied from the book and input by hand):

select groups.name, COUNT(*) num_customers
from
(
select sum(a.avail_balance) cust_balance
from account a
inner join product p
on a.product_cd = p.product_cd
where p.product_type_cd = 'ACCOUNT'
group by a.cust_id
) cust_rollup
inner join
(
select 'Small Fry' name, 0 low_limit, 4999.99 high_limit
union all
select 'Average Joe' name, 5000 low_limit, 9999.99 high_limit
union all
select 'Heavy Hitter' name, 10000 low_limit, 99999999.99 high_limit
) groups
on cust_rollup.cust_balance
between groups.low_limit and groups.high_limit
group by groups.name;

but get the following MySQL error message

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups on cust_rollup.cust_balance between groups.low_limit and groups.high_li' at line 18

I am running SQL WorkBench v8.0

Alun Griffiths  Feb 28, 2020 
Printed Page 175
first line

there are 3 customers, actually is 13

HuangLing  Jan 17, 2019 
Printed Page 182
Exercise 9-3

The start and end dates listed in the subquery are too low to produce interesting results (no "workers" or "mentors"). As the start dates in the employee table begin in 2004.

I am enjoying the book!

Thanks

David  Aug 17, 2010 
Printed Page 207
2nd code sample

The alias of the table "individual" has throughout the book been lowercase "i" and appears as such here in "i.lname" and "i.cust_id", but it is defined here as uppercase "I", probably confused with the label 'I' that appears in the same query. In a query, this would not generate an error, because MySQL is not case-sensitive. Nonetheless, it is clearly a typo and could confuse readers.

Specifically, "FROM individual I" should read "FROM individual i". Lowercase "i", not uppercase "I".

P.S. Loving the book!

Carl Smith  Aug 28, 2013 
Printed Page 208
1st paragraph/sql example

The example is showing accounts opened in the years 2000 through 2005:

SELECT YEAR(open_date) year, COUNT(*) how_many
FROM account
WHERE open_date > '1999-12-31'
AND open_date < '2006-01-01'
GROUP BY YEAR(open_date);

+------+----------+
| Year | how_many |
+------+----------+
| 2000 | 3 |
| 2001 | 4 |
| 2002 | 5 |
| 2003 | 3 |
| 2004 | 9 |
+------+----------+
5 rows in set (0.00 sec)

Correct me if I'm wrong, but isn't year 2005 is missing from this result set? Even if there were no accounts opened in 2005 shouldn't the year still show up with '0' in the second column?

Eric Ruscitti  Sep 14, 2009 
Printed, PDF Page 214
Handling Null Values

This query works as printed:

SELECT emp_id, fname, lname,
CASE
WHEN title IS NULL THEN 'Unknown'
ELSE title
END
FROM employee;

But would greatly benefit from a column alias, e.g.:

SELECT emp_id, fname, lname,
CASE
WHEN title IS NULL THEN 'Unknown'
ELSE title
END 'Employee Tltle'
FROM employee;

Peter Fales  Nov 01, 2019 
Printed Page 220
1st paragraph

In the first paragraph: "...then attempts to remove $500 from the checking account and add it to the savings account."

All other references in this section of the book are taking $500 from the savings account and transferring it to the checking account.

Eric Ruscitti  Sep 15, 2009 
238
Check Constraints section

Check constraints are listed, but there aren't any examples or discussion of them in the chapter.

Anonymous  Dec 12, 2009 
Printed Page 262
middle of page

It's ProcessList, not Process_List

Anonymous  Jul 20, 2010 
PDF Page 272
Appendix A - ERD

According to description of the notation, there should be a 1-to-many relationship between customer and individual, and customer and business. The line from customer to individual uses the "crows foot" with a zero, indicating that for a particular customer there can be zero, one, or "many" individuals. (And same for business)

However, according to the schema, the Foreign Key (FK) for individual is also the primary key meaning that there can only be one row with that value. And there must be at least one because the primary key can't be null. So the ERD should show this as a 1-to-1 relationship between customer and individual (or customer and business) rather than 1-to-many.

Peter Fales  Mar 09, 2020 
287
C.1.4. 3-4

Incomplete answer.

On Page 60 Exercise 3-4, there is a "-> ORDER BY <4>, <5>;". However, the answer does not have the Order By completed.

So what is the complete answer?

Anonymous  Sep 07, 2010 
Printed Page 288
Example 3-4

The answer for Example 3-4 on page 288 doesn't match the example shown on page 60. The example on page 60 has an ORDER BY clause and two "arguments" (i.e. <4> and <5>) that are missing from the answer page.

Anonymous  Nov 24, 2009 
Printed Page 289
Exercise 3-4 answer key

For exercise 3-4 (on page 60), answers for only the first 3 questions/blanks are provided in Appendix C on page 289. Answers for questions/blanks 4 and 5 are missing.

Melinda Campbell  Jun 08, 2009 
PDF Page 290
4-3 Answer

I think that the answer for 4-3 could also (more concisely) be:

SELECT * FROM account WHERE YEAR(open_date) = 2002;

Not really an error but another possible answer.




Daniel Miller  Jan 13, 2014 
Printed Page 292
Appendix C

Hi,

I am not sure why changing the alias in the on subclause results in a different return set

mysql> select e.emp_id, e.fname, e.lname
-> from employee e inner join employee e_mgr
-> on e_mgr.superior_emp_id = e.emp_id <===============
-> where e.dept_id != e_mgr.dept_id;
+--------+--------+-----------+
| emp_id | fname | lname |
+--------+--------+-----------+
| 3 | Robert | Tyler |
| 4 | Susan | Hawthorne |
+--------+--------+-----------+
2 rows in set (0.00 sec)


mysql> select e.emp_id, e.fname, e.lname
-> from employee e inner join employee mgr
-> on e.superior_emp_id = mgr.emp_id <===============
-> where e.dept_id != mgr.dept_id;
+--------+-------+-----------+
| emp_id | fname | lname |
+--------+-------+-----------+
| 4 | Susan | Hawthorne |
| 5 | John | Gooding |
+--------+-------+-----------+
2 rows in set (0.00 sec)

David  Jul 25, 2009 
299
Solution for Example 10-1

[Nit] The provided question asks for product name:

"Write a query that returns all product names along with the accounts based on that ..."

but the provided solution uses the product_code:

SELECT p. product_cd, a.account_id, a.cust_id, a.avail_balance
FROM product p LEFT OUTER JOIN account a
ON p. product_cd = a.product_cd;

Therefore, my answer was slightly different:
SELECT p.name product_name, a.account_id FROM product p
LEFT OUTER JOIN account a
ON p.product_cd = a.product_cd;







Anonymous  Dec 11, 2009 
303
Solution for 12-1

The solution uses

"INTO @cst_id, @mm_id, @chk_id"

which I don't think was ever introduced in the book.

Anonymous  Dec 11, 2009 
304
Solution for 13-1

Unique constraint used in solution, but wasn't covered in the chapter.

Anonymous  Dec 12, 2009 
Printed Page 308
Output for 15-2 answer

Not an error, just a fyi.

If you enter the "ALTER TABLE employee ADD INDEX emp_names_idx (lname, fname)" line from page 231, then the output in in 15-2 will also have:

ALTER TABLE employee ADD INDEX emp_names_idx (lname,
fname);

I think this should be mentioned in the appendix as it makes the answer easier to understand (i.e. what st.seq_in_index is being used for).

Eric White  Jan 19, 2015