Pages
338
Published
2009
Learning SQL
A practical introduction to SQL for querying, filtering, and managing relational databases
Build a solid foundation in SQL so you can query, shape, and manage data with confidence in any relational database.
Learning SQL by Alan Beaulieu gives you a structured, hands-on path through the language that powers nearly every relational database in production today. Starting from the basics of data modeling and the SELECT statement, the book builds toward multi-table joins, subqueries, aggregation, transactions, and set-based thinking. You finish with the skills to write correct, readable SQL against real schemas — not just toy examples.
About this book
SQL is the language that sits between you and your data. Whether you are a developer writing application queries, an analyst pulling reports, or a database administrator keeping systems healthy, you need SQL to do your job well. Learning SQL gives you that foundation without assumptions and without shortcuts.
Alan Beaulieu starts with the relational model — what tables, rows, and keys actually mean — before moving to the SELECT statement. That ordering matters. Readers who understand how a database organizes data write better queries from day one, because they can reason about what the engine is doing rather than guessing at syntax.
The book progresses in a logical sequence. You learn filtering with WHERE before grouping with GROUP BY. You learn inner joins before outer joins. Each chapter introduces one concept, applies it to a working database, and builds on what came before. By the time you reach subqueries and set operations, you have the vocabulary to understand why those tools exist and when to reach for them.
Key areas the book covers:
- The relational model and how data is organized in tables, rows, and columns
- Filtering, sorting, and limiting result sets with WHERE, ORDER BY, and LIMIT
- Joining multiple tables with INNER, OUTER, CROSS, and self-joins
- Aggregating data with GROUP BY, HAVING, and common aggregate functions
- Subqueries, derived tables, and correlated subqueries
- Set operations: UNION, INTERSECT, and EXCEPT
- Inserting, updating, and deleting data safely
- Transactions, locking, and basic concurrency concepts
The examples run against MySQL, but the concepts transfer directly to PostgreSQL, SQL Server, Oracle, and SQLite. SQL is largely portable at the level this book operates, and Beaulieu notes where dialects differ so you are never confused when your environment behaves slightly differently.
This is not a reference manual. It is a teaching book, written to be read in order. If you have struggled with SQL tutorials that throw syntax at you without explanation, this book is the corrective. You will finish it knowing not just what to type but why it works.
🎯 What you'll learn
- Model data correctly by understanding the relational model and how primary and foreign keys enforce integrity
- Write SELECT statements that filter, sort, and shape result sets exactly as needed
- Join two or more tables using inner, outer, cross, and self-joins without producing accidental Cartesian products
- Aggregate and summarize data with GROUP BY and HAVING to answer real analytical questions
- Use subqueries and derived tables to break complex queries into readable, maintainable pieces
- Modify data safely with INSERT, UPDATE, and DELETE, understanding how transactions protect you from partial failures
- Apply set operations like UNION and INTERSECT to combine results from multiple queries
- Read and reason about query execution so you can troubleshoot unexpected results rather than guessing at fixes
👤 Who is this book for?
- Developers who interact with relational databases daily but have never had formal SQL instruction
- Analysts and data professionals who need to write their own queries instead of relying on exported spreadsheets
- Computer science students who want a practical complement to a theory-heavy database course
- Backend engineers learning a new stack that includes MySQL, PostgreSQL, or another relational database
- Technical professionals who learned just enough SQL to get by and want to fill the gaps systematically
Table of contents
-
01
A Little Background
Introduces the history of the relational model and explains how databases organize data into tables, rows, and columns. You learn the vocabulary you will use for the rest of the book.
-
02
Creating and Populating a Database
Walks through creating a sample MySQL database and populating it with data. You set up the working schema used in every subsequent chapter.
-
03
Query Primer
Introduces the SELECT statement and its core clauses. You write your first queries against real tables and learn how the database processes a query.
-
04
Filtering
Covers the WHERE clause in depth, including comparison operators, BETWEEN, IN, LIKE, and NULL handling. You learn to isolate exactly the rows you need.
-
05
Querying Multiple Tables
Explains how joins work and when to use INNER, OUTER, CROSS, and self-joins. You combine data from two or more tables without producing incorrect or duplicate results.
-
06
Working with Sets
Introduces set operations — UNION, UNION ALL, INTERSECT, and EXCEPT — and shows how to combine result sets from separate queries into a single output.
-
07
Data Generation, Manipulation, and Conversion
Covers built-in functions for strings, numbers, and dates, as well as type conversion. You learn to transform raw column values into the format your query needs.
-
08
Grouping and Aggregates
Explains GROUP BY, HAVING, and aggregate functions such as COUNT, SUM, AVG, MIN, and MAX. You write queries that summarize large datasets into meaningful totals and statistics.
-
09
Subqueries
Introduces scalar, column, and correlated subqueries as well as derived tables. You learn to nest queries to solve problems that a single SELECT statement cannot handle cleanly.
-
10
Joins Revisited
Returns to joins with a deeper treatment of outer joins, cross joins, and natural joins. You refine your understanding of when each join type is appropriate.
-
11
Conditional Logic
Covers the CASE expression and how to embed conditional logic directly inside a query. You use CASE to pivot data, categorize values, and avoid multiple round trips to the database.
-
12
Transactions
Explains what a transaction is, how COMMIT and ROLLBACK work, and what locking means for concurrent users. You learn to group data modifications so they succeed or fail as a unit.
Frequently asked questions
Do I need any prior programming experience to read this book?
No prior programming experience is required. The book assumes you know what a database is in general terms but teaches SQL from the first principle. Comfort reading plain text is all you need to get started.
Which database does the book use for its examples?
All examples run against MySQL. The core SQL covered is standard enough to apply directly to PostgreSQL, SQL Server, Oracle, and SQLite, and the book notes where syntax differs between systems.
Is this book suitable for someone who already knows basic SQL?
It depends on how much you know. If you can write a simple SELECT with a WHERE clause but get stuck on joins, subqueries, or aggregation, you will find the middle and later chapters genuinely useful. If you are already comfortable with those topics, this book may cover ground you have already mastered.
The publication date is 2009. Is the SQL still relevant?
Core SQL — SELECT, joins, aggregation, transactions — has not changed in any meaningful way since this book was published. The syntax you learn here works against current versions of MySQL, PostgreSQL, and every other major relational database.
Does the book include exercises or practice problems?
Each chapter includes exercises at the end so you can test your understanding before moving on. Working through them is the fastest way to confirm you have absorbed the material.
How long is the book and how long will it take to read?
The book is 338 pages. A focused reader covering one or two chapters per session should complete it in two to three weeks, with time to work through the exercises.