You know the rudiments of the SQL query language, yet you feel you aren't taking full advantage of SQL's expressive power. You'd like to learn how to do more work with SQL inside the database before pushing data across the network to your applications. You'd like to take your SQL skills to the next level. Let's face it, SQL is a deceptively simple language to learn, and many database developers never go far beyond the simple SELECT columns FROM table WHERE conditions. But there is so much more you can do with the language. In the SQL Cookbook , experienced SQL developer Anthony Molinaro shares his favorite SQL techniques and features. You'll learn
Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo "When it comes down to it, we all go to work, we all have bills to pay, and we all want to go home at a reasonable time and enjoy what's still available of our days." The SQL Cookbook moves quickly from problem to solution, saving you time each step of the way.
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.
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.
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!
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 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.
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
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.
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.
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.
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.
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.
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.
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.
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.
"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.