Errata

Head First SQL

Errata for Head First 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
Printed Page xxxiv
1st paragraph, end of second line

Pathetic misspelled as "pathtetic"

Anonymous  Feb 02, 2017 
Other Digital Version Chapter 8 section natural join
the last inner join: natural join

In the resulting table, the last row says "Bobby" for the boy column and "harmonica" for the toy column. The toy column should be "baseball cards" since Bobby's toy_id is 5 and so is "baseball cards" in the toys table. The "harmonica" toy_id is 4 and has no matches with the toy_id in the boys table. There is also an arrow message pointing to the resulting table that says "We get the same result set as we did with our first inner join, the equijoin". This isn't true since the equijoin table has a different result for Bobby. The equijoin table is correct.

Anonymous  Oct 06, 2022 
Printed Page 1
104

Magnet matching solutions :

For the second WHERE clause, the following is given as answer :
WHERE cow_name LIKE '_sie' ;

Result given : Elsie

Two pages prior we learned that the underscore '_' was a stand-in for just one unknown character. So it wouldn't work wit'El' before sie.

Shouldn't the WHERE clause be the following :

WHERE cow_name LIKE '%sie' ;

Thank you for your attention, I am an absolute beginner in the field and your book is very nice to understand the concepts.

Marc Piras  Nov 15, 2020 
Printed Page 17, 24, 37, 59, etc.
The "Watch it!" box

In all the "Watch it!" boxes, the TV image belies the full text.
For example, at the page 37 Watch it box, what is readable is:
Order matters!
....should be listed in
....same order as the
....mes.

Anonymous  Dec 11, 2011 
Printed Page 24
Description pointing to BLOB character

The description reads, "Call him BLOB. He likes large gobs of text data". This should read "Call him BLOB. He likes large gobs of binary data" as BLOB stands for Binary Large OBject.

Anthony Geoghegan  Dec 19, 2011 
PDF Page 25
in the answer to the second question

Where it says: "size of table"
it should say: "size of the table" or "size of your table"

gabkdlly  Oct 08, 2012 
ePub Page 39
last code example in exercise, before "What's Wrong?", followed by a note that this can hang the db.

In the example last entry has a apostrophe (') whereas in the solution this apostrophe is on purpose missing to produce the error.
So the SQL-statement in the question/exercise does not produce any error as expected.

Anonymous  Oct 17, 2013 
Other Digital Version 39
last code example in exercise, before "What's Wrong?", followed by a note that this can hang the db.

In the example last entry has a apostrophe (') whereas in the solution this apostrophe is on purpose missing to produce the error.
So the SQL-statement in the question/exercise does not produce any error as expected.

Location 1076 of 10324 in kindle edition.

Anonymous  Jul 09, 2014 
Printed Page 90
4th Question

The solution is "SELECT drink_name, color, ice FROM drink_info WHERE cost >= 3.8;

There are 3 drinks that meet this criteria.

Soda and It @ 3.8
Greyhound @ 4
Kiss on the Lips @ 5.5

If you left out the '=', it would work.

Arthur Neville  Aug 19, 2011 
Printed Page 92
third picture

Placement of the drink_info table does not make sense. It is necessary to place the table easy_drink.

George  Apr 24, 2020 
Printed Page 115
Solution to the First Query

The answer for this query:

SELECT drink_name FROM easy_drinks
WHERE main IN ('peach nectar', 'soda');
is
| Blue Moon |
| Oh My Gosh |
| Hot Gold |
| Lone Tree |
| Greyhound |
| Soda and It |

While the solution query (obtained by rewriting the above mentioned query) as given in the book is:

SELECT drink_name FROM easy_drinks
WHERE main BETWEEN 'P' and 'T';
is
| Blue Moon |
| Oh My Gosh |
| Lime Fizz |
| Hot Gold |
| Lone Tree |
| Greyhound |
| Soda and It |

Note: The extra Lime Fizz in the second query. Lime Fizz has main as Sprite (refer page 84 in the book). So both the queries do not give us the same number of rows.


Anonymous  Jan 21, 2012 
Printed Page 115
United States

The original query is:
mysql> select * from easy_drinks where main IN ('peach nectar', 'soda');

For me that returns:
+-------------+
| drink_name |
+-------------+
| Blue Moon |
| Oh My Gosh |
| Hot Gold |
| Lone Tree |
| Soda and It |
| Greyhound |
+-------------+

The answer in the book is:
select drink_name from easy_drinks where main between 'p' and 't';
+-------------+
| drink_name |
+-------------+
| Blue Moon |
| Oh My Gosh |
| Lime Fizz |
| Hot Gold |
| Lone Tree |
| Soda and It |
| Greyhound |
+-------------+

Because Lime Fizz contains Sprite.

The correct answer is:
select drink_name from easy_drinks where main between 'p' and 'sp';
+-------------+
| drink_name |
+-------------+
| Blue Moon |
| Oh My Gosh |
| Hot Gold |
| Lone Tree |
| Soda and It |
| Greyhound |
+-------------+

Luke Petschauer  May 28, 2014 
Printed Page 142
5th Query

WHERE last_seen = 'Oakland Hospital' OR last_seen = 'Dickson Park';

The answer for this is given in the text as Deletes Bonzo's and Scooter's records along with the old records for Mr. Hobo. The answer should actually be Snuggles instead of Bonzo.

Anonymous  Jan 24, 2012 
Printed Page 208
1st sentence

There's a missing space, e.g.

"to get us started,and" should be
"to get us started, and"

Jon Forrest  Feb 10, 2016 
Printed Page 212
source code, middle of page

instead of
ALTER TABLE project_list
MODIFY COLUMN proj_desc VARCHAR(120);

it should read
ALTER TABLE project_list
MODIFY proj_desc VARCHAR(120);
(i.e. without "COLUMN")

Anonymous  Mar 03, 2014 
PDF, ePub, Mobi Page 219
column year

The (recent, corrected) solution still does not work. There are two problems with it.

1) MySQL does not support FIFTH, SIXTH etc in an ALTER TABLE statement. It only supports FIRST and AFTER. See the ALTER TABLE syntax reference here: http://dev.mysql.com/doc/refman/5.5/en/alter-table.html
Note that this affects page 201 and 202 also.

2) Even when using FIRST or AFTER in an ALTER TABLE statement, you need to specify the data type.

See this transcript (which includes my corrected solution):
--------------------------------
mysql> CREATE TABLE `hooptie` (
-> `color` varchar(20) default NULL,
-> `year` varchar(4) default NULL,
-> `make` varchar(20) default NULL,
-> `mo` varchar(20) default NULL,
-> `howmuch` float(10,3) default NULL
-> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> INSERT INTO `hooptie` (`color`,`year`,`make`,`mo`,`howmuch`) VALUES ('sil
ver','1998','Porsche','Boxter','17992.539');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO `hooptie` (`color`,`year`,`make`,`mo`,`howmuch`) VALUES (NULL
,'2000','Jaguar','XJ','15995.000');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO `hooptie` (`color`,`year`,`make`,`mo`,`howmuch`) VALUES ('red
','2002','Cadillac','Escalade','40215.898');
Query OK, 1 row affected (0.00 sec)

mysql> ALTER TABLE hooptie
-> RENAME TO car_table,
-> ADD COLUMN car_id INT NOT NULL AUTO_INCREMENT FIRST,
-> ADD PRIMARY KEY (car_id),
-> ADD COLUMN VIN VARCHAR(17) AFTER car_id,
-> CHANGE COLUMN mo model VARCHAR(20),
-> MODIFY COLUMN color AFTER model,
-> MODIFY COLUMN year SIXTH,
-> CHANGE COLUMN howmuch price DECIMAL(7,2);
ERROR 1064 (42000): 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 'AFTER
model,
MODIFY COLUMN year SIXTH,
CHANGE COLUMN howmuch price DECIMAL(7,2)' at line 7

mysql> ALTER TABLE hooptie
-> RENAME TO car_table,
-> ADD COLUMN car_id INT NOT NULL AUTO_INCREMENT FIRST,
-> ADD PRIMARY KEY (car_id),
-> ADD COLUMN VIN VARCHAR(17) AFTER car_id,
-> CHANGE COLUMN mo model VARCHAR(20),
-> MODIFY COLUMN color varchar(20) AFTER model,
-> MODIFY COLUMN year varchar(4) AFTER color,
-> CHANGE COLUMN howmuch price DECIMAL(7,2);
Query OK, 3 rows affected, 2 warnings (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 2

mysql> select * from car_table;
+--------+------+----------+----------+--------+------+----------+
| car_id | VIN | make | model | color | year | price |
+--------+------+----------+----------+--------+------+----------+
| 1 | NULL | Porsche | Boxter | silver | 1998 | 17992.54 |
| 2 | NULL | Jaguar | XJ | NULL | 2000 | 15995.00 |
| 3 | NULL | Cadillac | Escalade | red | 2002 | 40215.90 |
+--------+------+----------+----------+--------+------+----------+
3 rows in set (0.00 sec)

Mike Cunneen  Feb 19, 2014 
Printed Page 229
first lot of indented text

UPDATE table_name
SET column_name = newvalue;

should be

UPDATE table_name
SET column_name = 'newvalue';


I found it confusing when different standards are used. eg: on page 147 there's a similar statement with the single apostrophes included.

I do understand that if it was an INT or DEC value they wouldn't be needed but it'd be nice if you had some sort of reminder in the book about this.

Anonymous  May 13, 2011 
PDF Page 242
3rd paragraph

On chapter 5, page 242 of pdf, Title "Alter and Change",
the query given to change the column number to proj_id and to make it primary key the query given is:

ALTER TABLE project_list
CHANGE COLUMN number proj_id INT NOT NULL AUTO_INCREMENT
ADD PRIMARY KEY ('proj_id');

But it is not working. Its giving error 1064.

After Modification the Correct command in my opinion would be:

ALTER TABLE project_list
CHANGE COLUMN number proj_id INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY(proj_id);

And now it is working.

Thanks.

Sujoy Mukherjee  Apr 30, 2015 
PDF, ePub Page 248
Case Construction Solution

When running the code from the solutions against the table, existing values in the 'category' column are erased where no 'WHEN' statement was provided (tested with MySQL 5.5.27).
Adding 'ELSE category' solved the issue for me (solution 2 and 3).

Sebastian Ryborz  Nov 29, 2013 
Printed Page 270
3rd Question (to write the sql query)

Order of the sql statement is incorrect. try it with this one...

SELECT first_name, COUNT(sale_date) FROM cookie_sales WHERE sales > 0 GROUP BY first_name;

Anonymous  Jan 16, 2013 
Printed Page 308
there are no Dumb Questions, last answer

The answer states that the CHECK constraint is not available in MySQL. This was true at the time of publishing, however as of MySQL 8.0.16 it is now available. See https://mysqlserverteam.com/mysql-8-0-16-introducing-check-constraint/

Yeshayohu Zirkind  Sep 01, 2020 
Printed Page 311
2nd paragraph

In the second paragraph on page 311 the text reads: "The prof_id column in my_contacts is a good example of a one-to-many relationship"

The prof_id column, however, does not exist in the table at this point in the text. It still exists as a column called "profession". There should be some discussion prior to this statement that shows the profession column being replaced with a prof_id column linking to a new professions table in a one-to-many relationship.

Jeff Counts  Mar 18, 2013 
PDF Page 311
2nd paragraph

Is confusing where it says "In this example, we’ve moved the profession column to a new child table, and changed the profession column in the parent table to a foreign key, the prof_id column.".

But above, in same chapter says that the table that contains the foreign key is the child table and the table with the primary key referenced is the parent table. Accordingly the parent table is 'professions' and the child table is 'my_contacts'.

Thanks.


Anonymous  Apr 03, 2015 
Printed Page 324
Sharpen your pencil solution box

It has already been acknowledged that "weakness is dependent on name" and "arch_enemy is dependent on name" are incorrect and should be deleted. For the same reasons given by Andrew Bate for those answers, the answer

"city is dependent on country"

should be changed to

"country is dependent on city".

If two rows agree on a value for city, then they will always agree on a value for country; not the other way around. Note that this applies to the data in the table but not generally (Wonder Waiter could move from Paris, France to Paris, US for example).

Benjamin Morgan  Feb 01, 2017 
Printed Page 327-328
First two questions

Why would the value in the copyright column change if the title or an author of a book changes?

Anonymous  Dec 16, 2021 
Printed Page 355
CREATE TABLE query

Not sure why you would create a table called profession and have the name of the profession column "mc_prof". Shouldn't it just be named profession?

I don't think the "mc_prof" alias in the SELECT statement should be used as the name of the profession column in the CREATE statement.

Jeff  Nov 01, 2013 
PDF Page 358
Freestanding paragraph, bottom left, second sentence.

Original:

If we had 5 results for boy and 4 for toys, you’d see a boy’s name grouped first.

Should be:

If we had 5 results for boy and 4 for toys, you’d see the results grouped by boys.

A.M. Sabuncu  Aug 06, 2017 
PDF Page 359
Last Q/A pair on the page.

Q: I’ve heard the terms “inner join” and “outer join” used before. Is this Cartesian join the same thing?

Since outer joins are covered later, and since the answer to the question does not involve an outer join, reference to an outer join is not necessary, and just serves to confuse the topic.

A.M. Sabuncu  Aug 06, 2017 
Printed Page 364
Center of page SELECT statement

Last line of SELECT statement reads:

...ON boys.toy_id = toys.toy_id;

This line caused an error in a PHP trial. I believe it should read,

...ON boys.boy_id = toys.toy_id;

I made the change in the code, and it worked fine. The boys table does not have a toy_id field.

William Sanders
 
Oct 13, 2011 
Printed Page 404
Bottom

"Answers on p. 407" is missing from bottom box.

Michael Peddycord  Jun 01, 2013 
Printed Page 425
Last paragraph

Tables show the name "Cleo" and descriptions use the name "Clea".

Dave Solomon  Apr 25, 2011 
Printed Page 426
Whole Page

In Left Outer Join The Explanation says that in query after from in left table and After ANY JOIN FLAVOUR is Right Table

But On 426 Page When Explaining right join the book points , after the from tab1 as right and after RIGHT OUTER JOIN as left table.

Anonymous  Apr 10, 2018 
Printed Page 448

The best solutions without subqueries.

1. List title for jobs that earn salaries equal to highest salary in the job_listing table.

SELECT a.title
FROM job_listing a, job_listing b
GROUP BY a.title, a.salary
HAVING a.salary = MAX(b.salary);

2. List the first and last name of people with a salary greater that the average salary.

SELECT mc.first_name, mc.last_name
FROM my_contacts mc
NATURAL JOIN job_current a
CROSS JOIN job_current b
GROUP BY mc.first_name, mc.last_name, a.salary
HAVING a.salary > AVG(b.salary);

Andrey Smelik  Mar 21, 2013 
Printed Page 458
3rd paragraph, under "He gets the status_id from the status table"

SELECT statement sources incorrect table.

SELECT status_id from profession WHERE status = 'single'
SHOULD BE
SELECT status_id from status WHERE status = 'single'

Kelly Kline  Nov 24, 2015 
Printed Page 461
Code example in the "CHECKing the gender" section.

The syntax of the CHECK constraint is incorrect, as the Boolean expression must be in parentheses, like so:

ALTER TABLE my_contacts
ADD CONSTRAINT CHECK (gender IN ('M', 'F'));

Benjamin Morgan  Feb 09, 2017 
Printed Page 462
Last sentence.

"You won't have end up with mystery values." Should likely be "You won't end up with mystery values."

Dave Solomon  Apr 27, 2011 
Printed Page 476
The first paragraph titled "Your view may be updatable if…"

The description presented is not that of an updatable view, but of an insertable view. Failing to include all of the NOT NULL columns in a view does not prevent it from being used to UPDATE or DELETE columns. The final paragraph on the page does point out conditions that prevent a view from being updatable, such as aggregate operators.

Furthermore, whether or not INSERT can be used actually depends on whether the view contains all of the columns for which a default value is not defined. It is possible to use INSERT on a view that does not contain all of the NOT NULL columns, provided those columns have a default value other than NULL.

Benjamin Morgan  Feb 10, 2017 
Printed Page 504
Second SQL statement, revoking grant option.

As you do elsewhere in the book, I recommend that you add a note to indicate that the following would not work on MySQL:

REVOKE GRANT OPTION ON
DELETE ON chores
FROM happy, sleepy;

MySQL does not allow you to remove the grant option on a specific command, only on a specific table; hence "DELETE ON" would have to be removed from the above.

Benjamin Morgan  Feb 12, 2017 
Printed Page 507
Fourth example

On both pages 507 & 508 example four has lowercase "on".

Dave Solomon  May 02, 2011 
Printed Page 509
Third "A:"

"The first asterisk refers to all database, the second to all tables." Database should probably be plural, as "databases".

Dave Solomon  May 02, 2011 
Printed Page 509
Last "A:"

No space between first and second sentences.

Dave Solomon  May 02, 2011 
Printed Page 521
7 Across

"OPTION allows user ito grant the role" should have "to" in place of "ito".

Dave Solomon  May 02, 2011 
Printed Page 535
First line of SQL code.

The syntax is not:

CAST(your_column, TYPE)

as given, but

CAST(your_column AS TYPE)

as used in the subsequent examples.

Benjamin Morgan  Feb 19, 2017 
Printed Page 555
Many-to-Many

"many rows in the first to match may rows in the" "may" should be "many"

Dave Solomon  May 03, 2011 
Printed Page 556
Lower left corner

There is no "R" for the terms that begin with "r" like there is for every other letter.

Dave Solomon  May 03, 2011 
Printed Page 556
Right Outer Join

"table and matches them to rows in LEFT table" There should probably be a "the" before LEFT.

Dave Solomon  May 03, 2011