Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


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.

Subscriber Reviews

Average Rating: 4.833333333333333 out of 5 rating Based on 6 Ratings

"worth reading" - by santosh on 19-DEC-2012
Reviewer Rating: 1 star rating2 star rating3 star rating4 star rating5 star rating
This is best book for learning T Sql.5 start
Report as Inappropriate

"I am using this book to keep sharp on my SQL" - by imjamin on 19-MAY-2011
Reviewer Rating: 1 star rating2 star rating3 star rating4 star rating5 star rating
The code in this book is not bad.  I  find myself saying"Hey that is not a bad idea".  Before I look at the answer I try to ask myself how I would accomplish such a task, try my answer, then try the authors.  For those who are beginning SQL my advice is that you create the database  then tables he uses (you must create them by hand), and then TYPE out the examples for your Brand of database.  Thank you for a good read Anthony M.
Report as Inappropriate

"Good practice examples among different DBs" - by Anonymous on 13-JUL-2010
Reviewer Rating: 1 star rating2 star rating3 star rating4 star rating5 star rating
Good practice examples among different DBs
Report as Inappropriate

Table of Contents



The publisher has provided additional content related to this title.


Visit the catalog page for SQL Cookbook

  • Catalog Page

Visit the errata page for SQL Cookbook

  • Errata

Download the supplemental electronic content for SQL Cookbook

  • Supplemental Content