Buy this Book
Print Book $29.99 PDF $27.99 Read it Now!
Print Book £20.99
Add to UK Cart
Reprint Licensing
SQL Hacks

By Andrew Cumming, Gordon Russell
First Edition  November 2006 
Pages: 410
Series: Hacks
ISBN 10: 0-596-52799-3 | ISBN 13: 9780596527990
starstarstarstarstar (Average of 5 Customer Reviews)

Buy 2 Get 1 Free Free ShippingGuarantee

Book description

Whether you're running Access, MySQL, SQL Server, Oracle, or PostgreSQL, this book will help you push the limits of traditional SQL to squeeze data effectively from your database. SQL Hacks offers 100 hacks -- unique tips and tools -- that bring you the knowledge of experts who apply what they know in the real world to help you take full advantage of the expressive power of SQL. You'll find practical techniques to address complex data manipulation problems.
Full Description

Whether you're running Access, MySQL, SQL Server, Oracle, or PostgreSQL, this book will help you push the limits of traditional SQL to squeeze data effectively from your database. The book offers 100 hacks -- unique tips and tools -- that bring you the knowledge of experts who apply what they know in the real world to help you take full advantage of the expressive power of SQL. You'll find practical techniques to address complex data manipulation problems. Learn how to:
  • Wrangle data in the most efficient way possible
  • Aggregate and organize your data for meaningful and accurate reporting
  • Make the most of subqueries, joins, and unions
  • Stay on top of the performance of your queries and the server that runs them
  • Avoid common SQL security pitfalls, including the dreaded SQL injection attack

Let SQL Hacks serve as your toolbox for digging up and manipulating data. If you love to tinker and optimize, SQL is the perfect technology and SQL Hacks is the must-have book for you.

Browse within this book

Cover | Table of Contents



Featured customer reviews

Write a Review


from the have-they-installed-SQL Server 2000-yet? dept,  June 22 2007
Rating: StarStarStarStarStar
Submitted by Anonymous Reader   [Respond | View]

I think you should read the preface where the author clearly states that this book is not designed to house clean code or show off the best design aspects but rather to provide hacks that get the job done. I think you should really be careful what you post rather than burn up a book that has saved so many others time and provided ideas on how to get things done.


from the have-they-installed-SQL Server 2000-yet? dept,  April 14 2007
Rating: StarStarStarStarStar
Submitted by Coding SQL Server since 6.5 but now running SQL Server 2005   [Respond | View]

The SQL Hacks book claims to support SQL Server 2005, however many of the code examples for SQL Server use SQL Seerver 7 syntax completely ignoring the proper way to write T-SQL for SQL Server 2K or 2005.

For instance, the book still uses the outdated @@Identity to retreive the last identity value. This was replaced 7 years ago by the improved identitiy_scope() function. Using @@identity risks getting the wrong value if a trigger inserts new rows. No one who write T-SQL code uses @@identity anymore.

Speaking of functions, the book also ignores T-SQL user-defined function which were introduced in SQL Server 2000. (even in the Can you write functions hack!)

Will the T-SQL code run? yes. Is it current code? in many places no.

Not only is the T-SQL poorly written code, but the hacks themselves are hit and miss. Some are clever, others are simply a first try at a task without really workgin it through.

More disturbing is the fact that I've entered this review before, but O'Reilly deletes it. hmmmm.




Great Book,  January 21 2007
Rating: StarStarStarStarStar
Submitted by Anonymous Reader   [Respond | View]

The sample code is available for download from from http://examples.oreilly.com/sqlhks/

The zip file includes SQL statements for each of the popular implementations. The DDL (data definition language) statements create the sample tables. The DML (data manipulation language) statements add sample data and show the hack.

All of the examples are relatively short and it is is easy to copy and paste the code.

Read all reviews


Great Book,  January 13 2007
Rating: StarStarStarStarStar
Submitted by guitarbuff0101   [Respond | View]

This Hacks book is very good and well written. I haven't yet downloaded the sample DDL or DML statements from the O'Reilly Website because they don't exist(?).

Well worth the investment in SQL HACKS for intermediate database techniques.


Fun book for exploring SQL,,  December 15 2006
Rating: StarStarStarStarStar
Submitted by Anonymous Reader   [Respond | View]

I have not had that much fun with SQL queries till I started reading and experimenting with SQL Hacks.

SQL is often taken much for granted and this books helps explore different ways of approaching SQL queries. The different DBMS vendors have their unique flavor of SQL which SQL Hacks admiringly encompasses.

This book is a great reference/tutorial for readers with differing backgrounds except for the most experienced DBAs.


Media reviews

"The authors did their homework, and SQL Hack's strengths are the depth, detail, and level of knowledge with which each database system is covered, and the book's willingness to get down and gritty. There's never an impression that juicy details were omitted because the authors didn't want to expend the effort to pick a colleague's brain or hunt down a factoid that never got documented elsewhere...The polish is top notch. Writing a book is a huge undertaking, and the economics of book publishing gives publishers little margin for advances. A book that reads like its third release but is actually in its first can only be the product of an exceptional level of dedication by the authors. "
-- Scrottie, Use Perl;

"Many of the recipes in SQL Hacks will improve the SQL you write day to day, and many will give you the confidence to attempt much more involved tasks with SQL. Other recipes will rarely if ever be needed, but make for a entertaining and education reading in a similar way that "worse case survival scenario" books do — SQL is pitted against the most difficult analysis tasks just as survival scenario books pit humans against pavement and lions. SQL Hacks fits well in the Hacks series, which raises the bar on advanced books by offering large, eclectic sets of tricks for problems that an unambitious person (a non-hacker) wouldn't ever push technology hard enough to run into. Put another way, the questions answered in a good Hacks book are ones that would get a "good question" comment rather than a an "RTFM!" response. It does a good job continuing where O'Reilly's SQL Cookbook left off, which is always difficult with two books written at slightly different times by different authors. Still, it's harder to review a Hacks book than a Learning book as, with hacks, the sky is the limit, and the reader will always find herself wishing for more. To this end, I hope O'Reilly continues to publish newer editions of their various Hacks books, drawing in more and more content in each edition, and identifying recipes that might better serve in the Cookbook counterpart."
-- Scott Walters, Slashdot.org

"SH (SQL Hacks) is simultaneously a programming romp and deadly serious to the people who think about a million customers or sales or measurements at a time. Cumming and Russell meet the challenge of balancing these two aspects — the exuberant and pragmatic — well...you could even use SH as a tutorial, especially if, like most database programmers, you do more reading than writing. SH is not a reference, but it's methodical enough that an alert and experienced programmer with no prior knowledge of SQL could probably learn all of the language he needs for most purposes. They even tackle the preliminaries of auditing, deployment, and administration, topics some programming introductions leave out. "
-- Cameron Laird, UnixReview.com

Read all reviews


See larger cover


"SQL Hacks fits well in the Hacks series, which raises the bar on advanced books by offering large, eclectic sets of tricks for problems that an unambitious person (a non-hacker) wouldn't ever push technology hard enough to run into."
--Scott Walters, Slashdot.org