Learning SQL by Alan Beaulieu

Learning SQL

  • Author: Alan Beaulieu
  • Softcover: 289 pages
  • Publisher: O’Reilly(August 22, 2005)
  • Book dimensions: 9.2 x 7.0 x 0.8 inches
  • ISBN: 0-596-00727-2
  • ITBookworm score: 3.0 /5


This is one of those books that seems to not have a solid home. The biggest question I asked myself when I got it was, do we really need another book on basic SQL? What we need are more books on advanced SQL and solving real-world problems. Still, this book takes you through the most basic SQL syntax and leads you all the way through relatively complicated statements. The reason I say it doesn’t seem to have a solid home is because it explains simple concepts in great detail assuming no knowledge from the user, and then skips over some other topics that really need more attention for an absolute beginner to understand. I’m just not entirely convinced that the book holds enough new material to warrant buying it over any of the other many beginning SQL books out there. One thing it does have though is exercises at the end of every chapter. I think it’s important for beginners to have as much practice as possible and this book offers some of that. None of the examples will push the reader to the limit of his skills, but they’re better than nothing. The one thing I felt could have really put this book out in front of the others was practical advice on what types of statements perform better in production and which ones come with severe penalties. To tell someone how to write a statement and not tell them when they should and shouldn’t use it will just breed another generation of developers who don’t know what they’re doing. It’s unfortunate that this book doesn’t offer any of that advice. Readers of this book will come out with a good knowledge of the SQL language though. If you do all the examples, and really try to understand the reasons why you’re doing something you should be alright.

Who is this book really for?

This is really a good question. I think the author may have had a hard time positioning this book because on the cover it says it’s for database developers and admins, but developers and admins should already know basic SQL. This book starts from ground zero and takes you through some pretty detailed SQL statements. In all, I would say this book is for the absolute beginner… someone who has never studied SQL before. The only real problem with that is that some things are explained rather well, while others appear to assume a certain level of knowledge and there’s no way a complete beginner would understand the topic with the explanation given.

Writing Style

I guess I can’t really say this book has a style. It doesn’t really offer anything entertaining, or anecdotal in any way. It’s straight forward, simple and not condescending though, so that’s good. I would say it probably rivals SQL Server Books Online in style… not necessarily boring, but not necessarily interesting either. If your goal is to learn the SQL language and get straight to the point, then this book will do it for you.


The book isn’t the best quality. The binding on mine started to separate while I was reading it. I only read the book once, so it isn’t falling apart, but I doubt it would stand up as a permenant reference.

Table of Contents

Chapter 1: A Little Background

I believe this first chapter sets the tone for the entire book. It’s both extremely basic, and somewhat confusing at the same time. It starts out with an explanation of what data is, and a very brief overview of basic normalization, what it’s good for, and some basic rules for duplicating data. The problem I see here is that this book says it’s for database developers and admins. Shouldn’t a database developer already know these extreme basics? I mean if a developer or admin doesn’t already know what a table is then you’ve got bigger problems than whether you can learn it from this book or not. The other problem here is that some things aren’t fully explained, so it would leave a true beginner in the dust quickly. It does give a brief history of SQL, but it completely contradicts what the industry as a standard believes. Most think that SQL stands for Structured Query Language, but the author states that it actually doesn’t stand for anything. After directly contradicting an accepted industry standard, I think you would need to back it up with a source for those who are going to doubt. I’m not saying he’s right or wrong, I’m just saying he needs to at least attempt to prove a statement like that. Now it goes into a bit of basic SQL. It shows a create table statement, a simple insert, and a simple select. Next it goes into a very brief description of MySQL. There’s really not much given here.

Chapter 2: Creating and Populating a Database

Starts out by walking through the basic steps of creating a MySQL database and a quick walkthrough of the command line utility. Next MySQL datatypes are overviewed. If you don’t know anything at all about datatypes then this will be a very good primer for you. It actually gives some good information about the specifics of the different types. Table creation is covered next with a bit of normalization. Now it talks about the different parts of an insert statement and how to generate auto-incrementing data. Basic updates and deletes are also discussed. An interesting section is that of bad SQL statements and how MySQL may respond to them. Mistakes such as nonunique PKs, column value violations, and invalid date conversions are given pretty equal attention.

Chapter 3: Query Primer

This chapter is exactly what it sounds like. It’s a very basic SQL primer that explains the different parts of a SQL statement. There’s nothing really special about it though. When I say there’s nothing special, I mean it from the perspective that there’s nothing here that you won’t find in any of the other basic SQL books. It is very thorough in the subjects it covers though talking about everything from the basics of a select to sub-queries, views, aliases, etc. I do like the fact that it has exercises at the end. Too many books don’t allow their readers the chance to practice what they’ve read.

Chapter 4: Filtering

This does a good job of discussing the where clause and all the operators. There are usually enough examples to get the point across but I feel that there are some topics that could be explained a bit better. Still, a good introduction to the where clause and how to form different kinds of statements. One thing that’s missing though is any kind of guidance in good coding practice. There are plenty of statements shown in different ways and using the various methods, but nowhere does it ever give any performance guidelines. I’m hoping this will come later in the book.

Chapter 5: Querying Multiple Tables

Joins, Joins, Join!!! Nothing but joins! Actually, pretty much nothing but inner joins. That’s ok though because quite often developers don’t have a very reasonable grasp of this topic, so I think dedicating a full chapter to it is justified. It gives some good examples of joins, and even covers triple joins and self joins. Though I really think that more discussion could have been given to self joins as well as joining a table more than once. It’s a pretty decent chapter though. One thing I found was that it gave syntax for the ‘using’ keyword instead of the regular ANSI syntax, and even stated that all the DBs support it. I tested it in SQL Server 2000 and I got a syntax error.

Chapter 6: Working with Sets

This is actually a very good chapter. Set operators are discussed pretty much in full. Union/Union all, Intersect, and Except are all given attention. It begins with a basic lesson in set theory for those who may not have studied it before. Then it moves into a discussion of the different operators, and even gets into operator precedence. It’s really a good primer on how the different operators work.

Chapter 7: Data Generation, Conversion, and Manipulation

Starts out talking about strings, string datatypes, and manipulations. It’s a pretty thorough discussion, but not all of it applies to SQL Server. Numbers and covered next. Math functions, precision, and signed data are covered. Nothing surprising… it’s all pretty basic, but a good tutorial. Next, temporal data is discussed in quite a bit of detail. A nice tutorial on time zones begins the discussion followed by generation, manipulation, and conversion of temporal data. In all, it’s a thorough chapter.

Chapter 8: Grouping and Aggregates

Starts out by talking about basic Group By and Having. It’s ok as basics go, but I think that someone who isn’t really adept at this sort of thing may need a little more explanation. It then moves into aggregate functions and implicit/explicit grouping. A good discussion of count() how and it handles expressions and nulls follows. Multi-column grouping is discussed next. I remember when I was first learning SQL, and I didn’t really understand multi-column grouping very well. One thing I found was that the author here shows you a single example of a query, but doesn’t really explain that SQL requires you to put all non-aggregated columns in the Group By clause. He mentions that he put it in there, but not that you absolutely have to. This section could have been expanded on a bit. Now we come to a quick paragraph on grouping with expressions, and I think it’s too quick. It would be nice, again, if he would have expanded on this a bit more and given some more examples. WITH ROLLUP and WITH CUBE are given a little attention as well. It’s nice to see for a change because few books bother to cover these two operators and they’ve fallen out of favor with many developers simply because they just don’t know it. The chapter finishes off by touching on the Having clause again. It doesn’t go into a lot of depth, but you’ll get the idea pretty well.

Chapter 9: Subqueries

This could easily turn out to be one of the most important chapters because subqueries are everywhere, and absolutely everyone needs to know how they work. This chapter starts out with a basic definition and a couple examples of subqueries. One place it fails right here at the beginning is in failing to explain why the subquery is necessary in these examples to begin with. It’s one thing to explain what something is, and how to use it, but it’s another thing to explain why it’s necessary in the first place. This goes along with what I said a couple chapters ago when I was talking about this book not explaining which methods are best and worst. Just because a method exists that doesn’t mean it should be used. Anyway, on with the chapter… Next it goes into types of subqueries: noncorreleated, and of course, correleated. Noncorrelated is first, and it starts by giving a definition and a couple examples. It then jumps into one of the most common errors and how to solve it using the IN operator. It actually discusses the IN operator and its many forms in some detail giving a few fairly practical examples. Then it goes into the ALL operator in some detail and gives some examples, and again, this operator is used very little so it’s good to keep these things alive. Next multi-column subqueries are given a little attention. It’s always reminded me of the fetch statement in a cursor. Correlated subqueries are discussed next, and I really don’t think they’re given the attention they deserve. I think that even in a basic discussion of a topic like this, there needs to be significant time given to why the subquery has to be correlated to begin with, and how you could do it otherwise, and what the performance differences are. This isn’t a topic that should be taken lightly, and so far this book offers no insight into what would be considered good practice. True, a developer won’t necessarily need to be told when and why to use this, but like everything else in this book, since it starts with the extreme basics, I believe that sets the tone and it should be followed, and some of these topics fully fleshed out. It does go on to talk about different reasons to use subqueries, but it’s not really what you would think. It doesn’t offer advice on when and when not to use them over other methods. What it does is just give you some different situations where they can be handy, but that’s hardly the same thing.

Chapter 10: Joins Revisited

Starts out talking about outer joins. It gives the difference between left and right outer joins is the left outer join indicates the table on the left side of the from clause. This is clearly incorrect because there are no tables on the left side of the from clause. It’s clear to me however, that what he means is that it’s the table on the left side of the join clause. However, to the beginner that this book is designed for, that’s an important distinction that could be confusing at first. Then, 3-way outer joins and self outer joins are quickly discussed with enough examples to get the point across. Next, cross joins are given attention, but nobody really cares about those much. Finally, there’s a small section on natural joins. I’ve never actually seen natural joins used in production (at least not that I can remember), so it’s not very common. I really feel that the shortness of this section is exactly what the topic deserves.

Chapter 11: Conditional Logic

This is another important chapter because conditional logic is everywhere in production DBs. It begins with CASE expressions. CASE is given a good bit of time, and is actually explained pretty well. Just about the time I started to get tired of it, it was over, so I say it was the perfect length. Selective aggregation is next, but it’s a very short section and really doesn’t tell you anything you couldn’t figure out from the other CASE logic section. Next it goes over how to use CASE to check for the existence of a record and display a value based off of that existence. It’s a very short section with only a couple examples, but it doesn’t really need more than that to understand the basics. Now it moves into some good advice on avoiding division by zero using CASE. Again, a really short section, but not much is needed here. Finally, making conditional updates is discussed, and while there’s not a lot of attention given to this, CASE is fairly easy to figure out, so by now the average reader will get what’s going on.

Chapter 12: Transactions

Starts out talking about the need for transactions and what a transaction is. It gives a basic definition, but relies on an example for any detail. The ACID properties we’ve come to expect from discussions about transactions weren’t even mentioned. As basic as this discussion is though, I’m not sure the reader won’t miss it. Next it has a couple quick sections on working with transactions. There’s not much real depth here thought, and I doubt there’s meant to be. If you want to know anything at all about transactions, then you’ll have to go outside this book.

Chapter 13: Indexes and Constraints

The chapter starts out with a discussion on indexes. It talks about the need for indexes, creation syntax, and different types of indexes. It then goes into a brief discussion on execution plans. I find the index discussion to be quite perfunctory. Nowhere does it even mention clustered indexes, or offer any real advice on what types of indexes to create and when. This chapter will give a beginner the idea that indexes exist, but this is the problem with many applications today. Nobody knows how to index. Indexes are almost the most important aspect to DB development, and while the author clearly considers this discussion to be out of the scope of this book, it really shouldn’t be. If developers don’t learn about indexes here, where will they learn it? Next we see 4 pages on constraints. The basics are covered pretty well, so I won’t complain too much about what’s not in there. It should suffice.


Leave a Reply

Your email address will not be published. Required fields are marked *