What do you think?


SQL Cookbook: Query Solutions and Techniques for All SQL Users
You may know SQL basics, but are you taking advantage of its expressive power? This second edition applies a highly practical approach to Structured Query Language (SQL) so you can create and manipulate large stores of data. Based on real-world examples, this updated cookbook provides a framework to help you construct solutions and executable examples in severalflavors of SQL, including Oracle, DB2, SQL Server, MySQL, andPostgreSQL.
SQL programmers, analysts, data scientists, database administrators, and even relatively casual SQL users will find SQL Cookbook to be a valuable problem-solving guide for everyday issues. No other resource offers recipes in this unique format to help you tackle nagging day-to-day conundrums with SQL.
The second edition includes:
Fully revised recipes that recognize the greater adoption of window functions in SQL implementations
Additional recipes that reflect the widespread adoption of common table expressions (CTEs) for more readable, easier-to-implement solutions
New recipes to make SQL more useful for people who aren't database experts, including data scientists
Expanded solutions for working with numbers and strings
Up-to-date SQL recipes throughout the book to guide you through the basics
SQL programmers, analysts, data scientists, database administrators, and even relatively casual SQL users will find SQL Cookbook to be a valuable problem-solving guide for everyday issues. No other resource offers recipes in this unique format to help you tackle nagging day-to-day conundrums with SQL.
The second edition includes:
Fully revised recipes that recognize the greater adoption of window functions in SQL implementations
Additional recipes that reflect the widespread adoption of common table expressions (CTEs) for more readable, easier-to-implement solutions
New recipes to make SQL more useful for people who aren't database experts, including data scientists
Expanded solutions for working with numbers and strings
Up-to-date SQL recipes throughout the book to guide you through the basics
567 pages, Paperback
First published December 16, 2005
Ratings & Reviews
Friends & Following
Create a free account to discover what your friends think of this book!
Community Reviews
Displaying 1 - 25 of 25 reviews
February 17, 2009
good stuff in this bitch
December 9, 2017
I read this book cover-to-cover rather than using it in the manner intended. The intention is that, when one has a problem to solve, one would find the most similar problem in the table of contents. The repetition of reading multiple similar solutions by reading the entire book helped solidify the concepts. I've read other reviews here that criticize the SQL Cookbook because using the table of contents in the manner intended might lead to a solution that depends on concepts explained in prior solutions. The solutions are not always self-contained. Such criticisms are valid and are part of the reason that I read the book in its entirety. I have since implemented much of the material in my work and have improved a great deal as a result. Highly recommended.
May 6, 2008
If you NEED to learn the amazingly complex and available functionality in SQL queries, this is the book for you. Simply explained and elegantly detailed, this book is truly a must have for anyone with any level of SQL expertise, from the new beginner to the seasoned veteran.
October 7, 2024
A Must-Have Guide for Solving Everyday SQL Problems (5/5⭐)
I really enjoyed SQL Cookbook by Anthony Molinaro and Robert de Graaf. It’s super helpful for solving everyday SQL problems, especially for developers, data analysts, and database admins. The book gives clear solutions for popular databases like Oracle, MySQL, and PostgreSQL. Even if you're not a SQL expert, this book helps you write better and faster queries.
I found the sections on Recursive Hierarchical Queries, Window Functions, and CTEs especially useful, and I’ve already used them in my projects. Definitely a must-have on your desk for quick reference!
I really enjoyed SQL Cookbook by Anthony Molinaro and Robert de Graaf. It’s super helpful for solving everyday SQL problems, especially for developers, data analysts, and database admins. The book gives clear solutions for popular databases like Oracle, MySQL, and PostgreSQL. Even if you're not a SQL expert, this book helps you write better and faster queries.
I found the sections on Recursive Hierarchical Queries, Window Functions, and CTEs especially useful, and I’ve already used them in my projects. Definitely a must-have on your desk for quick reference!
March 6, 2008
You too can write SQL like the Jedi of old.
January 30, 2022
Perfect , Perfect and Perfect For Non-Experience and Seniors
August 28, 2020
Overall, one of the best SQL references out there !
I love how the book is structured : problem/solution/discussion, it is such a stimulating way to learn.
I also think some of the recipes are extremely useful (e.g. 13.4, 6.6, 9.10, 14.1, 14.2, 12.14, 12.13 and much more !). I have encountered many situations in which I would have liked to have read this book earlier.
Finally, I think the Appendix B is interesting and challenging although quite redundant (some solutions are almost exactly the same as other ones in the same chapter).
I have found some mistakes here and there in the book (https://www.reddit.com/r/SQL/comments...) but if I had a point to make, it would probably be about the complexity of the solutions proposed. Sometimes, I feel like the solutions are overshooting so much the original problem. For instance :
Appendix B, Question 12 : "You want to find students who take all courses"
Solution proposed :
SELECT sno,sname,age
FROM
(SELECT s.sno,s.sname,s.age,
COUNT(t.cno) OVER (PARTITION BY s.sno) AS cnt,
COUNT(distinct c.title) OVER() AS total,
ROW_NUMBER() OVER(PARTITION BY s.sno ORDER BY c.cno) AS rn
FROM courses c
LEFT JOIN take t ON (c.cno = t.cno)
LEFT JOIN student s ON (t.sno = s.sno)
) x
WHERE cnt = total
AND rn = 1
Seemingly equivalent solution :
SELECT t.sno, COUNT(*) as cnt
FROM [take] t
GROUP BY t.sno
HAVING COUNT(*) = (SELECT COUNT(DISTINCT cno) FROM [take])
I whish the book was prioritizing parsimony a little bit more, but maybe I'm just missing something
I love how the book is structured : problem/solution/discussion, it is such a stimulating way to learn.
I also think some of the recipes are extremely useful (e.g. 13.4, 6.6, 9.10, 14.1, 14.2, 12.14, 12.13 and much more !). I have encountered many situations in which I would have liked to have read this book earlier.
Finally, I think the Appendix B is interesting and challenging although quite redundant (some solutions are almost exactly the same as other ones in the same chapter).
I have found some mistakes here and there in the book (https://www.reddit.com/r/SQL/comments...) but if I had a point to make, it would probably be about the complexity of the solutions proposed. Sometimes, I feel like the solutions are overshooting so much the original problem. For instance :
Appendix B, Question 12 : "You want to find students who take all courses"
Solution proposed :
SELECT sno,sname,age
FROM
(SELECT s.sno,s.sname,s.age,
COUNT(t.cno) OVER (PARTITION BY s.sno) AS cnt,
COUNT(distinct c.title) OVER() AS total,
ROW_NUMBER() OVER(PARTITION BY s.sno ORDER BY c.cno) AS rn
FROM courses c
LEFT JOIN take t ON (c.cno = t.cno)
LEFT JOIN student s ON (t.sno = s.sno)
) x
WHERE cnt = total
AND rn = 1
Seemingly equivalent solution :
SELECT t.sno, COUNT(*) as cnt
FROM [take] t
GROUP BY t.sno
HAVING COUNT(*) = (SELECT COUNT(DISTINCT cno) FROM [take])
I whish the book was prioritizing parsimony a little bit more, but maybe I'm just missing something
January 10, 2023
This is a chore to get through. I stopped reading around 24% through. I guess it's not for me.
The book is very thorough in describing how to do stuff on different SQL databases, namely: MySQL, PostgreSQL, DB2, Oracle, and SQL Server. The problem is that I don't care about most of the databases! I mainly use MySQL (actually MariaDB).
If you have the patience to fast forward through the vendor-specific sections that you don't care about, the book has many interesting and challenging recipes.
Unfortunately the code in many recipes is hard to read! E.g. the author may create an intermediate (helper) table and name it "x" so you don't have a clue what the table holds. :(
Each chapter contains between 7 and 18 recipes around a similar theme. The chapters are:
1. Retrieving records
2. Sorting query results
3. Working with multiple tables
4. Inserting, updating, and deleting
5. Metadata queries
6. Working with strings
7. Working with numbers
8. Date arithmetic
9. Date manipulation
10. Working with ranges
11. Advanced searching
12. Reporting and reshaping
13. Hierarchical queries
14. Odds 'n' ends
Appendix A: Window function refresher
Appendix B: Common table expressions
The book is very thorough in describing how to do stuff on different SQL databases, namely: MySQL, PostgreSQL, DB2, Oracle, and SQL Server. The problem is that I don't care about most of the databases! I mainly use MySQL (actually MariaDB).
If you have the patience to fast forward through the vendor-specific sections that you don't care about, the book has many interesting and challenging recipes.
Unfortunately the code in many recipes is hard to read! E.g. the author may create an intermediate (helper) table and name it "x" so you don't have a clue what the table holds. :(
Each chapter contains between 7 and 18 recipes around a similar theme. The chapters are:
1. Retrieving records
2. Sorting query results
3. Working with multiple tables
4. Inserting, updating, and deleting
5. Metadata queries
6. Working with strings
7. Working with numbers
8. Date arithmetic
9. Date manipulation
10. Working with ranges
11. Advanced searching
12. Reporting and reshaping
13. Hierarchical queries
14. Odds 'n' ends
Appendix A: Window function refresher
Appendix B: Common table expressions
August 24, 2009
Thumbed through this initially and found some new tricks right away. So far it's been easy to find things for specific problems I need to solve.
April 28, 2020
I mean, just the best. This was like a little bible for me when i was learning MS SQL on the job. It had a purpose. It met that purpose. Pretty simple.
May 8, 2025
SQL Cookbook is my go-to resource for both deep dives into SQL logic and quick memory refreshers. I really like that it includes examples in multiple SQL dialects, which is helpful when working across different systems like PostgreSQL and MySQL. The examples are simple, practical, and easy to follow—perfect for both learning and quick reference. It’s one of the few technical books I keep coming back to time and time again. Highly recommended for anyone working with SQL—whether you're just starting out or looking to sharpen your skills.
March 23, 2020
Rather good. A bit dated in spots, bit the core ideas are still solid. Nice to see some solutions to problems I came up with (as a SQL autodidact) that I thought were"hacky" were actually the canonical way if solving those sorts of problems. I see now clearly some of the strengths and weaknesses of specific SQL flavors now, too. Lastly, I should be using window functions more.
March 27, 2020
Libro con queries avanzadas, en caso de que no tengas mucho conocimiento de SQL te recomiendo algún libro introductorio como la serie de "dummies" y posteriormente continúes con este o se puede volver confuso. Muestra diferentes funciones y sus aplicaciones en la vida real.
Libro interesante.
Libro interesante.
March 27, 2022
Abbriviations for fields and table names used in queries like: emp, empno, deptno, cnt, sal, mgrs, prez, smen and others make reading the examples hard and set a very bad example for writing good readable queries. Other than that it is a great book.
May 5, 2024
While it provides valuable insights overall, some chapters may fall short in clarity or relevance. Despite this, its comprehensive coverage and practical recipes still make it a worthwhile resource for SQL practitioners seeking to enhance their skills.
February 14, 2019
I purchased this as an eBook in a Humble Bundle and boy was that a bargain! I'm glad to have this in my dev toolkit; it's already informed and inspired some of my work.
September 8, 2020
Why would anyone want to read something like this when you can just Google everything? Never mind. 😑
November 18, 2021
Some useful snippets of information on the various SQL flavours but could be too simple for advanced users.
March 19, 2022
Good cookbook but a not enough on joins. Joins are the backbone of all SQL work and i felt like there was some missed opportunity there to really teach that subject well.
December 14, 2023
It's great book for you to start learning sql
read more here: https://unigap.io/
read more here: https://unigap.io/
December 28, 2016
The book covers many RDBMs, it is categorized by different topics, each topic contains many recipes. The recipes are well organized from most simple to more complex, so it takes you step by step to learn the details of each topic. Also there is a well documented description of queries. I like it a lot! So why I rated it 3/5 ? Because it is boring! And it has many repetitions of same ideas across recipes, and some recipes will not be understood unless you read first the previous recipe which makes it hard to randomly jump to a recipe. But in general it serves as a very good book to learn about SQL different topics and it use-cases in a "problem-solution" approach, with some amazing tricks which bring your 'Aha!' moments ;) ... Worth reading, especially that it won't take so much of your time; because you do not have to read each solution's description if you understand how the solution works.
October 3, 2017
"SQL Cookbook" by Anthony Molinaro is an invaluable resource for developers and database administrators.
The book is well-organized and structured, starting with the simplest and moving on to more complex recipes. It covers the most commonly used RDBMS, which is incredibly helpful for understanding them, not just the one you're currently using. The book is well-written with clear and easy-to-understand descriptions of queries, making it accessible even if you're unfamiliar with specific keyword usage.
I found the Oracle solutions beneficial, and the book is a great reference that taught me a lot of valuable tricks. In addition, the book contains many examples that I will likely use in the future, and I know I'll be coming back to it again and again.
The book is well-organized and structured, starting with the simplest and moving on to more complex recipes. It covers the most commonly used RDBMS, which is incredibly helpful for understanding them, not just the one you're currently using. The book is well-written with clear and easy-to-understand descriptions of queries, making it accessible even if you're unfamiliar with specific keyword usage.
I found the Oracle solutions beneficial, and the book is a great reference that taught me a lot of valuable tricks. In addition, the book contains many examples that I will likely use in the future, and I know I'll be coming back to it again and again.
September 13, 2007
great book for those who occasionally use sql, but don't want/need to learn it from head to toe.
Read
February 3, 2016Focused on the Oracle solutions. Great reference book that will teach you a lot of neat tricks.
February 1, 2018
This is too much for me.
Displaying 1 - 25 of 25 reviews






















