SQL Cookbook (Cookbooks (O'Reilly))

SQL Cookbook (Cookbooks (O'Reilly))
by Anthony Molinaro

SQL Cookbook (Cookbooks (O'Reilly))
List Price: $39.95
Our Price: $21.99
You Save: $17.96 (45%)
Availability: Usually ships in 1-2 business days
Buy Used: from $16.59 (click here)
Category: Book
See more book details and other editions


(Click here)
Buy this book at online book store in your country
Canada | UK | Germany | France

Book Summary Information

Author: Anthony Molinaro
Edition: Paperback
Audio: English (Unknown); English (Original Language); English (Published)
Published: 2005-12-23
ISBN: 0596009763
Number of pages: 640
Publisher: O'Reilly Media

Book Reviews of SQL Cookbook (Cookbooks (O'Reilly))

Book Review: Good tutorial on and selection of recipes solving problems with SQL
Summary: 5 Stars

Ultimately, the goal of this book is to give you a glimpse of what can be done using SQL outside of what is considered the typical SQL problem domain. This text is unique in that the target audience is wide, incorporating all levels of SQL programmers as well as those who are completely unfamiliar with SQL.

Both complex and simple solutions are provided, and solutions for five different vendors are available when a common solution does not exist. These five databases are DB2 v.8, Oracle Database 10g (with the exception of a handful of recipes, the solutions will work for Oracle8i Database and Oracle9i Database as well), PostgreSQL 8, SQL Server 2005 and MySQL 5. All of the examples are built around a small set of tables containing employee data. This helps the reader get familiar with the example data, so that, having become familiar with the data, you can focus on the technique that each recipe illustrates.

Chapter 1, Retrieving Records, introduces very simple queries. Examples include how to use a WHERE clause to restrict rows from your result set, providing aliases for columns in your result set, using an inline view to reference aliased columns, using simple conditional logic, limiting the number of rows returned by a query, returning random records, and finding NULL values. Most of the examples are very simple, but some of them appear in later more complex recipes, so it's a good idea to read this chapter if you're relatively new to SQL or aren't familiar with any of the examples listed for this chapter.

Chapter 2, Sorting Query Results, introduces recipes for sorting query results. The ORDER BY clause is introduced and is used to sort query results. Examples increase in complexity ranging from simple, single-column ordering, to ordering by substrings, to ordering based on conditional expressions.

Chapter 3, Working with Multiple Tables, introduces recipes for combining data from multiple tables. If you are new to SQL or are a bit rusty on joins, this is a good chapter to read before going on to Chapter 5 and later. Joining tables is what SQL is all about; you must understand joins to be successful. Examples in this chapter include performing both inner and outer joins, identifying Cartesian productions, basic set operations (set difference, union, intersection), and the effects of joins on aggregate functions.

Chapter 4, Inserting, Updating, Deleting, introduces recipes for inserting, updating, and deleting data, respectively. Most of the examples are very straightforward, perhaps even pedestrian. Nevertheless, operations such as inserting rows into one table from another table, the use of correlated subqueries in updates, an understanding of the effects of NULLs, and knowledge of new features such as multi-table inserts and the MERGE command are extremely useful for your toolbox.

Chapter 5, Metadata Queries, introduces recipes for getting at your database metadata. It's often very useful to find the indexes, constraints, and tables in your schema. The simple recipes here allow you to gain information about your schema. Additionally, "dynamic" SQL examples are shown here as well, i.e., SQL generated by SQL.

Chapter 6, Working with Strings, introduces recipes for manipulating strings. SQL is not known for its string parsing capabilities, but with a little creativity, usually involving Cartesian products, along with the vast array of vendor-specific functions, you can accomplish quite a bit. Some of the more interesting examples include counting the occurrences of a character in a string, creating delimited lists from table rows, converting delimited lists and strings into rows, and separating numeric and character data from a string of alphanumeric characters.

Chapter 7, Working with Numbers, introduces recipes for common number crunching. You'll learn how easily window functions solve problems involving moving calculations and aggregations. Examples include creating running totals; finding mean, median, and mode; calculating percentiles; and accounting for NULL while performing aggregations.

Chapter 8, Date Arithmetic, is the first of two chapters dealing with dates. Being able to perform simple date arithmetic is crucial to everyday tasks. Examples include determining the number of business days between two dates, calculating the difference between two dates in different units of time (day, month, year, etc.), and counting occurrences of days in a month.

Chapter 9, Date Manipulation, is the second of the two chapters dealing with dates. In this chapter you will find recipes for some of the most common date operations you will encounter in a typical work day. Examples include returning all days in a year, finding leap years, finding first and last days of a month, creating a calendar, and filling in missing dates for a range of dates.

Chapter 10, Working with Ranges, introduces recipes for identifying values in ranges, and for creating ranges of values. Examples include automatically generating a sequence of rows, filling in missing numeric values for a range of values, locating the beginning and end of a range of values, and locating consecutive values.

Chapter 11, Advanced Searching, introduces recipes that are crucial for everyday development and yet sometimes slip through the cracks. These recipes are not any more difficult than others, yet many developers make very inefficient attempts at solving the problems these recipes solve. Examples from this chapter include finding knight values, paginating through a result set, skipping rows from a table, finding reciprocals, selecting the top n records, and ranking results.

Chapter 12, Reporting and Warehousing, introduces queries typically used in warehousing or generating complex reports. Examples include converting rows into columns and vice versa (cross-tab reports), creating buckets or groups of data, creating histograms, calculating simple and complete subtotals, performing aggregations over a moving window of rows, and grouping rows based on given units of time.

Chapter 13, Hierarchical Queries, introduces hierarchical recipes. Regardless of how your data is modeled, at some point you will be asked to format data such that it represents a tree or parent-child relationship. This chapter provides recipes accomplishing these tasks. Creating tree-structured result sets can be cumbersome with traditional SQL, so vendor-supplied functions are particularly useful in this chapter. Examples include expressing a parent-child relationship, traversing a hierarchy from root to leaf, and rolling up a hierarchy.

Chapter 14, Odds 'n' Ends, is a collection of miscellaneous recipes that didn't fit into any other problem domain, but that nevertheless are interesting and useful. This chapter is different from the rest in that it focuses on vendor-specific solutions only. This is the only chapter of the book where each recipe highlights only one vendor. In some cases, though, you'll be able to easily tweak a solution provided in this chapter to work for a platform not covered in the recipe.

Appendix A, Window Function Refresher, is a window function refresher along with a solid discussion of groups in SQL. Window functions are new to most, so it is appropriate that this appendix serves as a brief tutorial. Additionally, the use of GROUP BY in queries is a source of confusion for many developers. This chapter defines exactly what a SQL group is, and then proceeds to use various queries as proofs to validate that definition. The chapter then goes into the effects of NULLs on groups, aggregates, and partitions. Lastly, you'll find discussion on the more obscure and yet extremely powerful syntax of the window function's OVER clause (i.e., the "framing" or "windowing" clause).

Appendix B, Rozenshtein Revisited, is a tribute to David Rozenshtein, author of "The Essence of SQL". Appendix B focuses on some of the queries presented in "The Essence of SQL", and provides alternative solutions using window functions (which weren't available when The Essence of SQL was written) for those queries.

I highly recommend this book for anyone working with or interested in working with SQL. However, you should already be familiar with the theory behind database management or you will have trouble with this book.

Summary of SQL Cookbook (Cookbooks (O'Reilly))

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.

Specific Databases Books

Book Subjects
Most talked about in Specific Databases Books
Navegar en Internet. Creación de un portal con PHP y MySQL. 3ª edición. ImageNavegar en Internet. Creación de un portal con PHP y MySQL. 3ª edición.
UNKNOWN; Perfect Paperback; Book
MySQL. Das Praxisbuch. ImageMySQL. Das Praxisbuch.
by Matthias Kannengiesser
Franzis; Published: 2003-06-01; Hardcover; Book
Best price: $32.33
PHP-MySQL avec Dreamweaver MX ImagePHP-MySQL avec Dreamweaver MX
by Jean-Marie Defrance
Eyrolles; Published: 2003-05-22; Paperback; Book
FileMaker Instant Web Publishing VTC Training CD ImageFileMaker Instant Web Publishing VTC Training CD
by David Wheelock
Virtual Training Company, Inc.; Published: 2007-04-04; CD-ROM; Book
Best price: $99.95
dBASE IV for Windows: A Developers Resource Book ImagedBASE IV for Windows: A Developers Resource Book
by Jack L. Hursch, Carolyn J. Hursch
Windcrest; Published: 1993-03; Paperback; Book
Price in other shops: $32.95
Head First SQL: Your Brain on SQL -- A Learner's Guide ImageHead First SQL: Your Brain on SQL -- A Learner's Guide
by Lynn Beighley
O'Reilly Media; Published: 2007-09-01; Paperback; Book
Best price: $20.00
Price in other shops: $44.99
Backup & Recovery: Inexpensive Backup Solutions for Open Systems ImageBackup & Recovery: Inexpensive Backup Solutions for Open Systems
by W. Curtis Preston
O'Reilly Media; Published: 2007-01-10; Paperback; Book
Best price: $25.55
Price in other shops: $49.99
Programming PHP ImageProgramming PHP
by Rasmus Lerdorf, Kevin Tatroe, Peter MacIntyre
O'Reilly Media; Published: 2006-05-05; Paperback; Book
Best price: $19.55
Price in other shops: $39.99
Inside the dBASE Professional Compiler ImageInside the dBASE Professional Compiler
by Tony Lima
John Wiley & Sons Inc (Computers); Published: 2000-12; Paperback; Book
Price in other shops: $32.95
dBASE IV Systems Development Handbook ImagedBASE IV Systems Development Handbook
by Beth Galdeiri
Prentice Hall Trade; Published: 1991-06; Hardcover; Book
Price in other shops: $49.95
Similar Books and other products
SQL Tuning ImageSQL Tuning
by Dan Tow
O'Reilly Media; Published: 2003-12-01; Paperback; Book
Best price: $22.62
Price in other shops: $39.95
Head First SQL: Your Brain on SQL -- A Learner's Guide ImageHead First SQL: Your Brain on SQL -- A Learner's Guide
by Lynn Beighley
O'Reilly Media; Published: 2007-09-01; Paperback; Book
Best price: $20.00
Price in other shops: $44.99
The Art of SQL ImageThe Art of SQL
by Stephane Faroult, Peter Robson
O'Reilly Media; Published: 2006-03-01; Paperback; Book
Best price: $21.95
Price in other shops: $44.99
SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers) ImageSQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)
by Bill Karwin
Pragmatic Bookshelf; Published: 2010-07-02; Paperback; Book
Best price: $19.23
Price in other shops: $34.95
Data Analysis Using SQL and Excel ImageData Analysis Using SQL and Excel
by Gordon S. Linoff
Wiley; Published: 2007-10-01; Paperback; Book
Best price: $27.16
Price in other shops: $45.00
SQL in a Nutshell (In a Nutshell (O'Reilly)) ImageSQL in a Nutshell (In a Nutshell (O'Reilly))
by Kevin Kline, Brand Hunt, Daniel Kline
O'Reilly Media; Published: 2008-12-02; Paperback; Book
Best price: $22.55
Price in other shops: $44.99
Sams Teach Yourself SQL in 10 Minutes (3rd Edition) ImageSams Teach Yourself SQL in 10 Minutes (3rd Edition)
by Ben Forta
Sams; Published: 2004-04-10; Paperback; Book
Best price: $12.65
Price in other shops: $24.99
Beginning SQL Joes 2 Pros: The SQL Hands-On Guide for Beginners (SQL Exam Prep Series 70-433 Volume 1 of 5) (Sql Design Series) ImageBeginning SQL Joes 2 Pros: The SQL Hands-On Guide for Beginners (SQL Exam Prep Series 70-433 Volume 1 of 5) (Sql Design Series)
by Rick A Morelan
BookSurge Publishing; Published: 2009-12-30; Paperback; Book
Best price: $17.39
Price in other shops: $25.00
SQL Pocket Guide (Pocket Guides) ImageSQL Pocket Guide (Pocket Guides)
by Jonathan Gennick
O'Reilly Media; Published: 2010-12-01; Paperback; Book
Best price: $8.31
Price in other shops: $14.99
Learning SQL ImageLearning SQL
by Alan Beaulieu
O'Reilly Media; Published: 2009-04-27; Paperback; Book
Best price: $22.35
Price in other shops: $39.99
Book store. Illustrated catalog of books on different categories