SQL Hacks

  Author:    Andrew Cumming, Gordon Russell, Gordon Russell
  ISBN:    0596527993
  Sales Rank:    141601
  Published:    2006-11-01
  Publisher:    O'Reilly Media, Inc.
  # Pages:    304
  Binding:    Paperback
  Avg. Rating:    5.0 based on 6 reviews
  Used Offers:    11 from $16.79
  Amazon Price:    $19.79
  (Data above last updated:  2008-09-06 06:38:25 EST)
  
  
Sort customer reviews by:
  
Show All Reviews on Page      Hide All Reviews on Page
   
  
SQL Hacks
  
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.

                  Reader Reviews 1 - 14 of 14                 
  
  
Review
Date
Review
Rating(5 High)
Review
Helpful
to:
Customer Review Reviewer
Info
Permanent
Link
Reader Reviews Below Sorted by Newest First
05-14-07 5 1\5
(Hide Review...)  Must have for any body concerned with SQL...
Reviewer Permalink
Provide tips on overcoming most common issues in SQL.
(Review Data Last Updated: 2008-05-25 06:02:22 EST)
05-13-07 5 1\6
(Hide Review...)  Must have for any body concerned with SQL...
Reviewer Permalink
Provide tips on overcoming most common issues in SQL.
(Review Data Last Updated: 2008-09-05 06:45:10 EST)
04-25-07 2 6\12
(Hide Review...)  Fairly lousy book. I expected better from O'Reilly
Reviewer Permalink
Two problems:

1. Huge quantity of typos and writing and technical errors.

2. It's definitely not "hacking" anything. At best (if it were corrected and proofread) it would be a typical cookbook: a number of loosely connected fragments of code for all kinds of potential scenarios. That's not bad, btw! But hacking it isn't. The word 'hacking' brings to mind an image of a Mad Genius as it were, but this book has absolutely nothing at this level. It's pretty much hum-drum SQL programming -- and I can see how it could be quite useful btw -- provided it didn't have so many egregious errors and typos. Snafus start right from the beginnning, and are at times mind boggling.

The book does have a lot of stuff, most of which is useful -- or rather it would be if you weren't afraid it's got errors in it. You can try of course, you can proofread this book yourself: and, paradoxically, this will be good learning. But personally, when it comes to technical books, I prefer to be able to trust that they're competent and well done, rather than play an amateur editor and try to fix it as I read it.

My recommendation: there's tons of similar stuff, so begin by looking for something else; if still interested, get the book into your hands and read a bit. See if you like it, see if you see errors, see if they bother you. In other words, do not buy this book sight inseen -- chances are high you will be disappointed. I regret that I didn't send this book back; YMMV of course.

Good luck.

----------

Examples:

1. Hack 11, p. 37. The goal is, I quote, "to show the date on which each customer purchased the most _totalitems_" [a tableful of data shown with columns "customer", "whn" [when, that is], and "totalitems"]. Here's the solution:

SELECT customer, whn, totalitems
FROM orders o1
WHERE o1.whn = (
SELECT MAX(whn)
FROM order o2
WHERE o1.customer = o2.customer
);

Why are we MAX'in on date? The result shows -- no surprises -- the latest date in the table, even though more items were sold on another date.

2. Hack 12, p 38. Here we adjust employee salaries based on their disciplinary record. None of this is important; what we do is produce a new salary which is the old one multiplied by something.

The solution is as follows: first, let's create a view with a calculated field with the new salary so we can look at it:

CREATE VIEW newSalary AS
SELECT id, CASE WHEN COUNT(emp) = 0 THEN salary + 100
WHEN COUNT(emp) > 1 THEN salary - 100
ELSE salary
END AS v
FROM employee LEFT JOIN disciplinary ON (id = emp)
GROUP BY id, salary;

So far so good, however: then we update the table itself, as follows:

UPDATE employee
SET slary = (SELECT v FROM newSalary
WHERE newSalary.id = employee.id)
WHERE id IN (SELECT id FROM newSalary);

Look at the second statement: what is the significance of the last WHERE check?

The newSalary is a *view* on the employee table, and it is a view that does not exclude any records -- so what exactly are we checking now? If you've got a record to update, it is already in ! The view is on the table, it IS the table, it doesn't matter if you look at a record directly in the table or through a view, it's one and the same set element. You can't find a record in the table that's not in the view!

3. Hack 13, "Choose the Right Join Style for Your Relationships", p.42 (typos): in the third paragraph, the reference to 'budget' table should have been to 'staff'; 'TRO2' should have been 'TR01'.

Also, at the very beginning, "When a relationship between tables is optional, you need an OUTER JOIN. When querying over many changes, if you require an OUTER JOIN you sometimes have to change all the other INNER JOINs into OUTER JOINs."

What does this mean? "When a relationship between tables is optional, you need an OUTER JOIN"? This doesn't mean a damn thing. Maybe it should be something like "an existing match" instead of "relationship"? I think so, but who knows...
(Review Data Last Updated: 2007-07-08 20:06:10 EST)
04-25-07 2 (NA)
(Hide Review...)  Fairly lousy book. I expected better from O'Reilly
Reviewer Permalink
Two problems: 1. Huge quantity of typos and writing and technical errors (I had a few examples in my previous review; this is my second attempt: the first review didn't stick , so just bear with me -- I'll try to restore some of it, but for now a shortened version. If you're impatient, off the top of my head I think you can look at Hacks 11, 12, and 13). 2. It's definitely not "hacking" anything. At best (if it were corrected and proofread) it would be a typical cookbook: a number of loosely connected fragments of code for all kinds of potential scenarios. That's not bad, btw! But hacking it isn't. The word 'hacking' brings to mind an image of a Mad Genius as it were, but this book has absolutely nothing at this level. It's pretty much hum-drum SQL programming -- and I can see how it could be quite useful btw -- provided it didn't have so many egregious errors and typos. Snafus start right from the beginnning, and are at times mind boggling. The book does have a lot of stuff, most of which is useful -- or rather it would be if you weren't afraid it's got errors in it. You can try of course, you can proofread this book yourself: and, paradoxically, this will be good learning. But personally, when it comes to technical books, I prefer to be able to trust that they're competent and well done, rather than play an amateur editor and try to fix it as I read it. My recommendation: there's tons of similar stuff, so begin by looking for something else; if still interested, get the book into your hands and read a bit. See if you like it, see if you see errors, see if they bother you. In other words, do not buy this book sight inseen -- chances are high you will be disappointed. I regret that I didn't send this book back; YMMV of course. Good luck. [PS. Everything gets jumbled together on this page, so I added the promised examples to the Comments section below]
(Review Data Last Updated: 2007-05-03 16:26:44 EST)
04-25-07 2 0\4
(Hide Review...)  Fairly lousy book. I expected better from O'Reilly.
Reviewer Permalink
Two problems: 1. Huge quantity of typos and writing and technical errors (I had a few examples in my previous review; this is my second attempt: the first review didn't stick , so just bear with me -- I'll try to restore some of it, but for now a shortened version. If you're impatient, off the top of my head I think you can look at Hacks 11, 12, and 13). 2. It's definitely not "hacking" anything. At best (if it were corrected and proofread) it would be a typical cookbook: a number of loosely connected fragments of code for all kinds of potential scenarios. That's not bad, btw! But hacking it isn't. The word 'hacking' brings to mind an image of a Mad Genius as it were, but this book has absolutely nothing at this level. It's pretty much hum-drum SQL programming -- and I can see how it could be quite useful btw -- provided it didn't have so many egregious errors and typos. Snafus start right from the beginnning, and are at times mind boggling. The book does have a lot of stuff, most of which is useful -- or rather it would be if you weren't afraid it's got errors in it. You can try of course, you can proofread this book yourself: and, paradoxically, this will be good learning. But personally, when it comes to technical books, I prefer to be able to trust that they're competent and well done, rather than play an amateur editor and try to fix it as I read it. My recommendation: there's tons of similar stuff, so begin by looking for something else; if still interested, get the book into your hands and read a bit. See if you like it, see if you see errors, see if they bother you. In other words, do not buy this book sight inseen -- chances are high you will be disappointed. I regret that I didn't send this book back; that said, YMMV of course. Good luck. [PS. I added the promised examples to the Comments section below]
(Review Data Last Updated: 2007-05-02 10:48:38 EST)
04-25-07 3 1\8
(Hide Review...)  2.5 stars. I expected better from O'Reilly
Reviewer Permalink
Two problems with this book:

1. HUGE number of typos and technical errors (some of them are so obvious that one wonders what the author was smoking when writing it, as well as what happened to his technical editor). I'll add examples later.

2. The word "hacking" brings to mind an image of a Mad Genius (breaking into the AT&T phone network ). That is, hacking is something that goes BEYOND simply being competent; hacking is ART. However, this book is at best a cookbook -- that is, it holds a fair amount of middle-ground, nothing-esoteric or groundbreaking kind of material. Shoulda been titled a "Cookbook".

Anything good here? Yeah, well, a lot of stuff that makes you say, ah, you can do that? neat. OK, so that's not bad. Another accidental benefit you can derive from reading this book is due to the huge number of errors. You bump into one and think, no, that can't be an error, this is a guru book, I must be missing the point, let's see again: thus it forces you to really prove it to yourself that what looks like junk indeed IS junk. Paradoxically, this improves your understanding -- at least by making you check and re-check everything with the help of other books and online docs. That's not what I expect from a technical book though, and plus, you end up never being sure if you did get it right.

I'll come back in a day or two and add specific examples. Needless to say, comments are welcome.


As promised, here are a few examples:

1. Hack 11, p. 37. The goal is, I quote, "to show the date on which each customer purchased the most _totalitems_" [a tableful of data shown with columns "customer", "whn" [when, that is], and "totalitems"]. Here's the solution:

SELECT customer, whn, totalitems
FROM orders o1
WHERE o1.whn = (
SELECT MAX(whn)
FROM order o2
WHERE o1.customer = o2.customer
);

Why are we MAX'in on date? The result shows -- no surprises -- the latest date in the table, even though more items were sold on another date. This is not a typo! The guy must have been high or something.

--------------------------------------

2. Hack 12, p 38. Here we adjust employee salaries based on their disciplinary record. None of this is important; what we do is produce a new salary which is the old one multiplied by something. The solution is as follows: first, let's create a view with a calculated field with the new salary so we can look at it:

CREATE VIEW newSalary AS
SELECT id, CASE WHEN COUNT(emp) = 0 THEN salary + 100
WHEN COUNT(emp) > 1 THEN salary - 100
ELSE salary
END AS v
FROM employee LEFT JOIN disciplinary ON (id = emp)
GROUP BY id, salary;

All's good so far. Then we update the table itself, as follows:

UPDATE employee
SET slary = (SELECT v FROM newSalary
WHERE newSalary.id = employee.id)
WHERE id IN (SELECT id FROM newSalary);

Look at the second statement: what is the significance of the last WHERE check? The newSalary is a *view* on the employee table, and it is a view that does not exclude any records -- so what exactly are we checking now? If you've got a record to update, it is already in ! The view is on the table, it IS the table, it doesn't matter if you look at a record directly in the table or through a view, it's one and the same set element. You can't find a record in the table that's not in the view!

------------------------------------------------------------------------

3. Hack 13, "Choose the Right Join Style for Your Relationships", p.42 (typos): in the third paragraph, the reference to 'budget' table should have been to 'staff'; 'TRO2' should have been 'TR01'.

Also, at the very beginning, "When a relationship between tables is optional, you need an OUTER JOIN. When querying over many changes, if you require an OUTER JOIN you sometimes have to change all the other INNER JOINs into OUTER JOINs."

What does this mean? "When a relationship between tables is optional, you need an OUTER JOIN"? This doesn't mean a damn thing. Maybe it should be something like "an existing match" instead of "relationship"? I think so, but who knows...
(Review Data Last Updated: 2007-04-27 21:32:42 EST)
03-09-07 4 1\1
(Hide Review...)  Mix of fun and useful information
Reviewer Permalink
I haven't found the book to be extremely useful, but it was a good read, with a few "that's another good way to do that" moments. It did get me interested in researching other topics I wasn't familiar with, bonus. If you work with SQL regularly you'll know a lot of this stuff. It is a fun easy read.
(Review Data Last Updated: 2007-04-12 14:33:54 EST)
03-08-07 4 1\1
(Hide Review...)  Mix of fun and useful information
Reviewer Permalink
I haven't found the book to be extremely useful, but it was a good read, with a few "that's another good way to do that" moments. It did get me interested in researching other topics I wasn't familiar with, bonus. If you work with SQL regularly you'll know a lot of this stuff. It is a fun easy read.
(Review Data Last Updated: 2007-04-11 12:02:10 EST)
01-19-07 5 2\4
(Hide Review...)  One of the best advanced SQL books I've seen
Reviewer Permalink
These hacks aren't for the beginning user, but for more advanced users. The authors explain the hacks, which can be written for any of a number of different databases, but then they explain necessary changes to allow a user of a differing db product to use the hacks as well.

MySQL, SQL Server, Postgres, Oracle among the ones covered.

If you are looking to make a step up from a decent database user to a very good one, this is a book for you.
(Review Data Last Updated: 2007-07-08 20:06:10 EST)
01-18-07 5 2\3
(Hide Review...)  One of the best advanced SQL books I've seen
Reviewer Permalink
These hacks aren't for the beginning user, but for more advanced users. The authors explain the hacks, which can be written for any of a number of different databases, but then they explain necessary changes to allow a user of a differing db product to use the hacks as well.

MySQL, SQL Server, Postgres, Oracle among the ones covered.

If you are looking to make a step up from a decent database user to a very good one, this is a book for you.
(Review Data Last Updated: 2007-03-08 19:56:36 EST)
01-09-07 5 11\13
(Hide Review...)  Good set of SQL tricks and tips if you have some experience
Reviewer Permalink
This book is a collection of 100 different hacks, ranging from the simple to the complex. Each hack involves a specific problem that you may have already seen before, but perhaps tackled in a way you wouldn't have considered. Where it is impossible to phrase a statement that is acceptable to all of MySQL, SQL Server, Oracle, and PostgreSQL, a form is used that is acceptable to at least two of the four. As MySQL is a relative newcomer, its designers have been able to build in compatibility with many of its competitors. For that reason, MySQL is usually one of the two systems that will accept the statement unchanged. That explains why most of the examples use the MySQL command-line utility. The MySQL examples are based around the version 5.0 release. However, many examples will work with the 4.2 release. Note that some hacks involve features such as referential integrity and transaction isolation, and these are implemented only for InnoDB tables and not for MyISAM tables.

The examples also work for Microsoft SQL Server 2005. The SQL Server 2000 version is good enough for all but those examples that use the RANK( ) function. PostgreSQL and Oracle users should have no problem using this book, and most of the hacks will run unchanged on both systems. Oracle has many so additional features that optimizations are not mentioned. There is also plenty here for Access users, but none of the required variations are mentioned for that database. The following is the table of contents:

Chapter 1, SQL Fundamentals - This is a gentle introduction to running SQL from the command line and programs. It also touches on simple SQL constructs. Even if you are already comfortable with SQL, you may find the flexibility of the SQL shown to be surprising and instructive.
Hack 1. Run SQL from the Command Line
Hack 2. Connect to SQL from a Program
Hack 3. Perform Conditional INSERTs
Hack 4. UPDATE the Database
Hack 5. Solve a Crossword Puzzle Using SQL
Hack 6. Don't Perform the Same Calculation Over and Over

Chapter 2, Joins, Unions, and Views - The hacks in this chapter concentrate on ways to use more than one table in your SQL. Different strategies are examined and discussed. If you find yourself using subqueries more than JOIN, you may also find the methods for converting subqueries to JOINs helpful.
Hack 7. Modify a Schema Without Breaking Existing Queries
Hack 8. Filter Rows and Columns
Hack 9. Filter on Indexed Columns
Hack 10. Convert Subqueries to JOINs
Hack 11. Convert Aggregate Subqueries to JOINs
Hack 12. Simplify Complicated Updates
Hack 13. Choose the Right Join Style for Your Relationships
Hack 14. Generate Combinations

Chapter 3, Text Handling - This chapter contains a number of hacks focused on efficient and effective text querying.
Hack 15. Search for Keywords Without LIKE
Hack 16. Search for a String Across Columns
Hack 17. Solve Anagrams
Hack 18. Sort Your Email

Chapter 4, Date Handling - Suppose you want to calculate the second Tuesday of each month, or look for trends based on the day of the week. Both calculations are discussed, as well as other hacks involving date processing and report generation techniques.
Hack 19. Convert Strings to Dates
Hack 20. Uncover Trends in Your Data
Hack 21. Report on Any Date Criteria
Hack 22. Generate Quarterly Reports
Hack 23. Second Tuesday of the Month

Chapter 5, Number Crunching - This chapter contains a host of hacks for handling numbers, from report generation to complex spatial calculations. This was my favorite chapter.
Hack 24. Multiply Across a Result Set
Hack 25. Keep a Running Total
Hack 26. Include the Rows Your JOIN Forgot
Hack 27. Identify Overlapping Ranges
Hack 28. Avoid Dividing by Zero
Hack 29. Other Ways to COUNT
Hack 30. Calculate the Maximum of Two Fields
Hack 31. Disaggregate a COUNT
Hack 32. Cope with Rounding Errors
Hack 33. Get Values and Subtotals in One Shot
Hack 34. Calculate the Median
Hack 35. Tally Results into a Chart
Hack 36. Calculate the Distance Between GPS Locations
Hack 37. Reconcile Invoices and Remittances
Hack 38. Find Transposition Errors
Hack 39. Apply a Progressive Tax
Hack 40. Calculate Rank

Chapter 6, Online Applications - Databases can help drive web sites, be directly controlled from a browser, and help close the gap between client and data. This chapter looks at a variety of hacks for using database systems in web-based activities.
Hack 41. Copy Web Pages into a Table
Hack 42. Present Data Graphically Using SVG
Hack 43. Add Navigation Features to Web Applications
Hack 44. Tunnel into MySQL from Microsoft Access
Hack 45. Process Web Server Logs
Hack 46. Store Images in a Database
Hack 47. Exploit an SQL Injection Vulnerability
Hack 48. Prevent an SQL Injection Attack

Chapter 7, Organizing Data - Hacks in this chapter are concerned with how data can be represented in a database, how data can be managed as it is stored and retrieved, and how errors in information can be detected, managed, and repaired.
Hack 49. Keep Track of Infrequently Changing Values
Hack 50. Combine Tables Containing Different Data
Hack 51. Display Rows As Columns
Hack 52. Display Columns As Rows
Hack 53. Clean Inconsistent Records
Hack 54. Denormalize Your Tables
Hack 55. Import Someone Else's Data
Hack 56. Play Matchmaker
Hack 57. Generate Unique Sequential Numbers

Chapter 8, Storing Small Amounts of Data - It is useful to parameterize queries using variables, treating the queries as functions and plugging in variables as needed. You can use standard SQL to provide parameterization, including variable scoping on a per-user or per-application basis. This chapter also looks at queries without tables, and support for inline tables.
Hack 58. Store Parameters in the Database
Hack 59. Define Personalized Parameters
Hack 60. Create a List of Personalized Parameters
Hack 61. Set Security Based on Rows
Hack 62. Issue Queries Without Using a Table
Hack 63. Generate Rows Without Tables

Chapter 9, Locking and Performance - This chapter examines some common issues, and presents a number of hacks on isolation levels, locking, query partitioning, and result set management, all aimed at improving query performance and minimizing delays.
Hack 64. Determine Your Isolation Level
Hack 65. Use Pessimistic Locking
Hack 66. Use Optimistic Locking
Hack 67. Lock Implicitly Within Transactions
Hack 68. Cope with Unexpected Redo
Hack 69. Execute Functions in the Database
Hack 70. Combine Your Queries
Hack 71. Extract Lots of Rows
Hack 72. Extract a Subset of the Results
Hack 73. Mix File and Database Storage
Hack 74. Compare and Synchronize Tables
Hack 75. Minimize Bandwidth in One-to-Many Joins
Hack 76. Compress to Avoid LOBs

Chapter 10, Reporting - SQL queries for report generation require a different approach than those used for real-time querying. This can allow you to trade query performance for readability and maintainability. This chapter includes a number of hacks for summarizing, processing, and analyzing report data.
Hack 77. Fill in Missing Values in a Pivot Table
Hack 78. Break It Down by Range
Hack 79. Identify Updates Uniquely
Hack 80. Play Six Degrees of Kevin Bacon
Hack 81. Build Decision Tables
Hack 82. Generate Sequential or Missing Data
Hack 83. Find the Top n in Each Group
Hack 84. Store Comma-Delimited Lists in a Column
Hack 85. Traverse a Simple Tree
Hack 86. Set Up Queuing in the Database
Hack 87. Generate a Calendar
Hack 88. Test Two Values from a Subquery
Hack 89. Choose Any Three of Five

Chapter 11, Users and Administration - This chapter presents a few useful hacks on user management, both in your applications and in your database systems. It also looks at the common pitfalls in packaging a database-enabled application for easy installation.
Hack 90. Implement Application-Level Accounts
Hack 91. Export and Import Table Definitions
Hack 92. Deploy Applications
Hack 93. Auto-Create Database Users
Hack 94. Create Users and Administrators
Hack 95. Issue Automatic Updates
Hack 96. Create an Audit Trail

Chapter 12, Wider Access - This chapter look at how to manage a diverse range of users who have SQL-level access to your databases.
Hack 97. Allow an Anonymous Account
Hack 98. Find and Stop Long-Running Queries
Hack 99. Don't Run Out of Disk Space
Hack 100. Run SQL from a Web Page

It is assumed that the reader is already familiar with database theory and their own particular flavor of SQL and just needs some "recipes" to get their job done. If you fall into this category, this book will make a fine addition to your reference books.
(Review Data Last Updated: 2007-06-24 14:14:05 EST)
01-08-07 5 2\2
(Hide Review...)  Good set of SQL tricks and tips if you have some experience
Reviewer Permalink
This book is a collection of 100 different hacks, ranging from the simple to the complex. Each hack involves a specific problem that you may have already seen before, but perhaps tackled in a way you wouldn't have considered. Where it is impossible to phrase a statement that is acceptable to all of MySQL, SQL Server, Oracle, and PostgreSQL, a form is used that is acceptable to at least two of the four. As MySQL is a relative newcomer, its designers have been able to build in compatibility with many of its competitors. For that reason, MySQL is usually one of the two systems that will accept the statement unchanged. That explains why most of the examples use the MySQL command-line utility. The MySQL examples are based around the version 5.0 release. However, many examples will work with the 4.2 release. Note that some hacks involve features such as referential integrity and transaction isolation, and these are implemented only for InnoDB tables and not for MyISAM tables.

The examples also work for Microsoft SQL Server 2005. The SQL Server 2000 version is good enough for all but those examples that use the RANK( ) function. PostgreSQL and Oracle users should have no problem using this book, and most of the hacks will run unchanged on both systems. Oracle has many so additional features that optimizations are not mentioned. There is also plenty here for Access users, but none of the required variations are mentioned for that database. The following is the table of contents:

Chapter 1, SQL Fundamentals - This is a gentle introduction to running SQL from the command line and programs. It also touches on simple SQL constructs. Even if you are already comfortable with SQL, you may find the flexibility of the SQL shown to be surprising and instructive.
Hack 1. Run SQL from the Command Line
Hack 2. Connect to SQL from a Program
Hack 3. Perform Conditional INSERTs
Hack 4. UPDATE the Database
Hack 5. Solve a Crossword Puzzle Using SQL
Hack 6. Don't Perform the Same Calculation Over and Over

Chapter 2, Joins, Unions, and Views - The hacks in this chapter concentrate on ways to use more than one table in your SQL. Different strategies are examined and discussed. If you find yourself using subqueries more than JOIN, you may also find the methods for converting subqueries to JOINs helpful.
Hack 7. Modify a Schema Without Breaking Existing Queries
Hack 8. Filter Rows and Columns
Hack 9. Filter on Indexed Columns
Hack 10. Convert Subqueries to JOINs
Hack 11. Convert Aggregate Subqueries to JOINs
Hack 12. Simplify Complicated Updates
Hack 13. Choose the Right Join Style for Your Relationships
Hack 14. Generate Combinations

Chapter 3, Text Handling - This chapter contains a number of hacks focused on efficient and effective text querying.
Hack 15. Search for Keywords Without LIKE
Hack 16. Search for a String Across Columns
Hack 17. Solve Anagrams
Hack 18. Sort Your Email

Chapter 4, Date Handling - Suppose you want to calculate the second Tuesday of each month, or look for trends based on the day of the week. Both calculations are discussed, as well as other hacks involving date processing and report generation techniques.
Hack 19. Convert Strings to Dates
Hack 20. Uncover Trends in Your Data
Hack 21. Report on Any Date Criteria
Hack 22. Generate Quarterly Reports
Hack 23. Second Tuesday of the Month

Chapter 5, Number Crunching - This chapter contains a host of hacks for handling numbers, from report generation to complex spatial calculations. This was my favorite chapter.
Hack 24. Multiply Across a Result Set
Hack 25. Keep a Running Total
Hack 26. Include the Rows Your JOIN Forgot
Hack 27. Identify Overlapping Ranges
Hack 28. Avoid Dividing by Zero
Hack 29. Other Ways to COUNT
Hack 30. Calculate the Maximum of Two Fields
Hack 31. Disaggregate a COUNT
Hack 32. Cope with Rounding Errors
Hack 33. Get Values and Subtotals in One Shot
Hack 34. Calculate the Median
Hack 35. Tally Results into a Chart
Hack 36. Calculate the Distance Between GPS Locations
Hack 37. Reconcile Invoices and Remittances
Hack 38. Find Transposition Errors
Hack 39. Apply a Progressive Tax
Hack 40. Calculate Rank

Chapter 6, Online Applications - Databases can help drive web sites, be directly controlled from a browser, and help close the gap between client and data. This chapter looks at a variety of hacks for using database systems in web-based activities.
Hack 41. Copy Web Pages into a Table
Hack 42. Present Data Graphically Using SVG
Hack 43. Add Navigation Features to Web Applications
Hack 44. Tunnel into MySQL from Microsoft Access
Hack 45. Process Web Server Logs
Hack 46. Store Images in a Database
Hack 47. Exploit an SQL Injection Vulnerability
Hack 48. Prevent an SQL Injection Attack

Chapter 7, Organizing Data - Hacks in this chapter are concerned with how data can be represented in a database, how data can be managed as it is stored and retrieved, and how errors in information can be detected, managed, and repaired.
Hack 49. Keep Track of Infrequently Changing Values
Hack 50. Combine Tables Containing Different Data
Hack 51. Display Rows As Columns
Hack 52. Display Columns As Rows
Hack 53. Clean Inconsistent Records
Hack 54. Denormalize Your Tables
Hack 55. Import Someone Else's Data
Hack 56. Play Matchmaker
Hack 57. Generate Unique Sequential Numbers

Chapter 8, Storing Small Amounts of Data - It is useful to parameterize queries using variables, treating the queries as functions and plugging in variables as needed. You can use standard SQL to provide parameterization, including variable scoping on a per-user or per-application basis. This chapter also looks at queries without tables, and support for inline tables.
Hack 58. Store Parameters in the Database
Hack 59. Define Personalized Parameters
Hack 60. Create a List of Personalized Parameters
Hack 61. Set Security Based on Rows
Hack 62. Issue Queries Without Using a Table
Hack 63. Generate Rows Without Tables

Chapter 9, Locking and Performance - This chapter examines some common issues, and presents a number of hacks on isolation levels, locking, query partitioning, and result set management, all aimed at improving query performance and minimizing delays.
Hack 64. Determine Your Isolation Level
Hack 65. Use Pessimistic Locking
Hack 66. Use Optimistic Locking
Hack 67. Lock Implicitly Within Transactions
Hack 68. Cope with Unexpected Redo
Hack 69. Execute Functions in the Database
Hack 70. Combine Your Queries
Hack 71. Extract Lots of Rows
Hack 72. Extract a Subset of the Results
Hack 73. Mix File and Database Storage
Hack 74. Compare and Synchronize Tables
Hack 75. Minimize Bandwidth in One-to-Many Joins
Hack 76. Compress to Avoid LOBs

Chapter 10, Reporting - SQL queries for report generation require a different approach than those used for real-time querying. This can allow you to trade query performance for readability and maintainability. This chapter includes a number of hacks for summarizing, processing, and analyzing report data.
Hack 77. Fill in Missing Values in a Pivot Table
Hack 78. Break It Down by Range
Hack 79. Identify Updates Uniquely
Hack 80. Play Six Degrees of Kevin Bacon
Hack 81. Build Decision Tables
Hack 82. Generate Sequential or Missing Data
Hack 83. Find the Top n in Each Group
Hack 84. Store Comma-Delimited Lists in a Column
Hack 85. Traverse a Simple Tree
Hack 86. Set Up Queuing in the Database
Hack 87. Generate a Calendar
Hack 88. Test Two Values from a Subquery
Hack 89. Choose Any Three of Five

Chapter 11, Users and Administration - This chapter presents a few useful hacks on user management, both in your applications and in your database systems. It also looks at the common pitfalls in packaging a database-enabled application for easy installation.
Hack 90. Implement Application-Level Accounts
Hack 91. Export and Import Table Definitions
Hack 92. Deploy Applications
Hack 93. Auto-Create Database Users
Hack 94. Create Users and Administrators
Hack 95. Issue Automatic Updates
Hack 96. Create an Audit Trail

Chapter 12, Wider Access - This chapter look at how to manage a diverse range of users who have SQL-level access to your databases.
Hack 97. Allow an Anonymous Account
Hack 98. Find and Stop Long-Running Queries
Hack 99. Don't Run Out of Disk Space
Hack 100. Run SQL from a Web Page

It is assumed that the reader is already familiar with database theory and their own particular flavor of SQL and just needs some "recipes" to get their job done. If you fall into this category, this book will make a fine addition to your reference books.
(Review Data Last Updated: 2007-01-19 11:50:46 EST)
12-15-06 5 3\5
(Hide Review...)  Fun book for exploring SQL
Reviewer Permalink
I have not had this 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.
(Review Data Last Updated: 2007-07-08 20:06:10 EST)
12-14-06 5 1\1
(Hide Review...)  Fun book for exploring SQL
Reviewer Permalink
I have not had this 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.
(Review Data Last Updated: 2007-01-09 13:54:48 EST)
  
                  Reader Reviews 1 - 14 of 14                 
  
  
  
  
  
  

Because the data used to generate this site come from outside sources, VeryWellSaid.com cannot guarantee the completeness or accuracy of the data.
Search VeryWellSaid™
Google
Web VeryWellSaid™
New subjects are added every week.
View Subjects Below by:
* Top Selling
 (click category name, left)
* Top-Rated Top Sellers
 (click 'Top Rated', right)
In the news...  
Dubai\UAE Top Rated
Influenza\Bird Flu Top Rated
Iraq Top Rated
Supreme Court Top Rated
All Books Top Rated
Arts Top Rated
Photography Top Rated
Digital Photography Top Rated
Digital Cameras Top Rated
Biography Top Rated
Business Top Rated
Management Top Rated
Marketing Top Rated
Sales Top Rated
Stocks Top Rated
Bonds Top Rated
Real Estate Top Rated
Trading Top Rated
Commodities Trading Top Rated
Time Management Top Rated
Starting A Business Top Rated
Children's Top Rated
Comics Top Rated
Computers Top Rated
PC Top Rated
Mac Top Rated
Programming Top Rated
Design Patterns Top Rated
.Net Top Rated
C# Top Rated
Vb.Net Top Rated
Asp.Net Top Rated
Java Top Rated
Python Top Rated
PHP Top Rated
Perl Top Rated
Javascript Top Rated
Ajax Top Rated
CSS Top Rated
Open Source Top Rated
SQL Top Rated
Databases Top Rated
Oracle Top Rated
MySql Top Rated
Sql Server Top Rated
IIS Top Rated
Apache Top Rated
Linux Top Rated
Windows Server Top Rated
Project Management Top Rated
HTML Top Rated
UML Top Rated
IT Certifications Top Rated
Cisco Certifications Top Rated
MCSE Top Rated
MCSD Top Rated
Cooking Top Rated
Italian Cooking Top Rated
Vegetarian Cooking Top Rated
Wine Top Rated
Engineering Top Rated
Entertainment Top Rated
Health Top Rated
Nutrition Top Rated
Dieting Top Rated
Sex Top Rated
History Top Rated
Military History Top Rated
British History Top Rated
Middle East History Top Rated
Land Battles Top Rated
Naval Warfare Top Rated
Air Warfare Top Rated
9/11 Top Rated
Terrorism Top Rated
Home Top Rated
Mortgage\Home Equity Loan Top Rated
Cars Top Rated
Car Buying Top Rated
Sports Cars Top Rated
Cat Top Rated
Humor Top Rated
Horror Top Rated
Law Top Rated
IP Law Top Rated
Legal History Top Rated
Fiction Top Rated
Oprah's Book Club Top Rated
Medicine Top Rated
Cancer Top Rated
Stroke Top Rated
Heart Disease Top Rated
Fertility Top Rated
Diabetes Top Rated
Pharmacology Top Rated
Back Problems Top Rated
Menopause Top Rated
Thyroid Top Rated
Pain Top Rated
Organic Chemistry Top Rated
Immune System Top Rated
Mystery Top Rated
Nonfiction Top Rated
Outdoors Top Rated
Running Top Rated
Radio Control Models Top Rated
Guns Top Rated
Parenting Top Rated
Divorce Top Rated
Professional Top Rated
Reference Top Rated
Religion Top Rated
Romance Top Rated
Science Top Rated
Physics Top Rated
Chemistry Top Rated
Astronomy Top Rated
Psychology Top Rated
Science Fiction Top Rated
Sports Top Rated
Teens Top Rated
Travel Top Rated
USA Top Rated
Europe Top Rated
France Top Rated
Italy Top Rated
England Top Rated
China Top Rated
All Books Arts Biography Click Here For An A-Z Index Of All 213 Best-Seller Subjects Business Children's Comics
Computers Cooking Engineering Entertainment Health History Home Horror Humor Law Fiction Medicine Mystery
Nonfiction Outdoors Parenting Professional Reference Religion Romance Science Sci-Fi Sports Teens Travel
In Association with Amazon.com

Cache miss
(not cached)