SQL Cookbook
Query Solutions and Techniques for Database Developers
Publisher: O'Reilly Media
Final Release Date: December 2005
Pages: 636

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 statement: 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 about:

  • Window functions, arguably the most significant enhancement to SQL in the past decade. If you're not using these, you're missing out

  • Powerful, database-specific features such as SQL Server's PIVOT and UNPIVOT operators, Oracle's MODEL clause, and PostgreSQL's very useful GENERATE_SERIES function

  • Pivoting rows into columns, reverse-pivoting columns into rows, using pivoting to facilitate inter-row calculations, and double-pivoting a result set

  • Bucketization, and why you should never use that term in Brooklyn.

  • How to create histograms, summarize data into buckets, perform aggregations over a moving range of values, generate running-totals and subtotals, and other advanced, data warehousing techniques

  • The technique of walking a string, which allows you to use SQL to parse through the characters, words, or delimited elements of a string

Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo is: "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.

Table of Contents
Product Details
About the Author
Recommended for You
Customer Reviews


by PowerReviews
oreillySQL Cookbook

(based on 8 reviews)

Ratings Distribution

  • 5 Stars



  • 4 Stars



  • 3 Stars



  • 2 Stars



  • 1 Stars



Reviewed by 8 customers

Sort by

Displaying reviews 1-8

Back to top


A true cookbook

By TupacAmaru

from Caribbean


  • Accurate
  • Concise
  • Easy to understand
  • Helpful examples
  • Well-written


    Best Uses

    • Expert
    • Intermediate
    • Novice
    • Student

    Comments about oreilly SQL Cookbook:

    A classic. An template example of what a every "cookbook" should be. Well written with an excellent problem solving approach.


    Not just a cookbook

    By Rory

    from London

    About Me Designer, Developer, Maker, Sys Admin

    Verified Reviewer



        Best Uses

        • Intermediate
        • Novice
        • Student

        Comments about oreilly SQL Cookbook:

        Don't be fooled by the title -- this is not just a "Cookbook".

        Through discussion of approaches to common SQL problems on various platforms the author provides insightful and practical advice on structuring queries and covers the gamut of need-to-know tools like pivoting, running totals, date differences between records and so on.

        The addendum on window functions and the aside on "Frege's Axiom and Russell's Paradox" are fascinating reading for any wannabe DBA and put the book into another league.

        I highly recommend this book.

        (2 of 2 customers found this review helpful)


        SQL Cookbook Does 'Fill the Bill'

        By John Spencer

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        The SQL Cookbook has helped me in so many ways that I cannot express enough appreciation to the author Anthony Molinaro.

        Especially well done are the short solutions. These make for a good foundation for developing quite complicated SQL code.

        I can see why a downloadable 'package' would be nice. However, since the solutions are short and the text that accompanies the solution is very to the point, I found it not particularly necessary for a downloadable set of source. Ah, but it would be nice...

        The coverage of the many many aspects SQL is quite amazing. The explanation of the 'window' functions is clear. I especially like the use of 'advanced' features early in the book and then seeing the explanations.

        The book does really help generate ideas--As I am sure the author intended.

        I will confess that I have two copies -- one a work and one at home. Overkill? I did not think so when I could grab the book for an solution/idea just about anywhere I happened to be.

        (1 of 2 customers found this review helpful)


        SQL Toolbox Must-Have

        By Larry

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        The thing I like about the O'Reilly 'Cookbook' series is that you may not have to use them for months, but when you need them they are there with the answers. And oftentimes finding the "one answer" that has been eluding you for hours or even days is worth the price of the book.

        This book falls into that category. What's really nice is that the author provides solutions for 5(!) different databases. And he does a good job explaining the solutions, making it easy to extrapolate them to solve similar queries.

        (5 of 9 customers found this review helpful)


        Not able to find code donload link!

        By Gurjeet

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        Hi there.

        The sql cook book book is really gr8...But some one pls tell me that where is the link to the code used in this book as this book doesnt have any cd an also there is no online link for code download...any help would me much appreciated!

        (2 of 3 customers found this review helpful)


        Excellent desktop resource book!

        By Roanoke Valley SQL Server Users Group

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        This book review was submitted by a Roanoke Valley SQL Server Users Group member as part of the Book Review Program.

        Reviewed by Harold Buckner

        This is a great book to have available at your fingertips. The table of contents is structured quite nicely and allows you to find what you need very quickly. The book covers a number of topics for solving everyday problems. It will also help you come up with ideas on how to go about handling particular queries by describing the problems and then listing possible solutions. And in these solutions you can find techniques on how to expand on them to resolve other issues.

        The author Anthony Molinaro, included a chapter on Metadata Queries that would be great for the beginner DBA wanting to find information about the database schema as well as other chapters on String manipulation, working with numbers, dates, warehousing and hierarchical queries. The author includes solutions for various platforms that I thought were nice to see how the different platforms handled the solutions. I also thought the author did a great job expanding the solution to help you understand what was happening.

        Great job Anthony and I hope to see more structured like this one.

        Harold Buckner

        (5 of 5 customers found this review helpful)


        A MUST HAVE book for anyone who works with real-world databases

        By vCurios

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        Discovering Anthony Molinaro's excellent book was pure serendipity and a wonderful one at that. For a while now I have been cobbling together notes on how to programmatically access some 300 servers variously hosting Microsoft SQL Server, MySQL, and Oracle. The cookbook covers these three (as well as IBM DB2 and PostgresSQL).

        I am 100% sure Mr. Molinaro's SQL Cookbook will save me dozens of hours of navigating through (a) the obtuse documentation of the three vendors and trying to sort out their respective dialects, and (b) the many well-meaning but poorly written SQL help sites that come up in Google. Indeed, as far as I am concerned, the book has already more than paid for itself in the time saved. A key strength of this cookbook (in addition to being very well written, edited, and produced) is it is very logically organized and makes it quite easy to find the topic you want.

        The only reason I gave it a four-star rating is that it doesn't have all the answers I need. If it did, it would have been a goldmine! But, seriously, if you are "SQL-challenged" like some of us (i.e., not an SQL guru), and you think your time is worth more than $40 an hour, you should get this book, even if you are working with just one of the three SQL platforms. If you are working with two or more versions, get this book, regardless!

        I'd like to take this opportunity to thank Mr. Molinaro for doing a great job helping me devote the time saved to other equally challenging adventures, like golf!

        (3 of 3 customers found this review helpful)


        Great stuff!

        By Dima

        from Undisclosed

        Comments about oreilly SQL Cookbook:

        Simply great stuff you won't find anywhere else!

        Displaying reviews 1-8

        Back to top

        Buy 2 Get 1 Free Free Shipping Guarantee
        Buying Options
        Immediate Access - Go Digital what's this?
        Ebook: $31.99
        Formats:  APK, DAISY, ePub, Mobi, PDF
        Print & Ebook: $43.95
        Print: $39.95