Joe Celko

Profile of Joe Celko

News & Commentary Posts: 19
Articles by Joe Celko

Celko SQL Puzzle: Calculating Commissions

How many ways can you come up with to keep track of commission amounts?... One way of spotting a design problem is when you have to use a VIEW or CTE over and over to answer basic questions. This implies that the schema has spread information over many tables that should be in one table or that it has aggregated data in one row that should be split out into multiple rows.

Post a Comment

Celko's Theater-Seat-Assignment SQL Puzzle

In many situations, auxiliary tables are faster and more appropriate than SQL with computations. To illustrate, consider a classic problem. You have a theater and a bunch of seats you wish to sell for a performance (or think of seats for an airline flight). The seats have a sequential serial number from 1 to (n) for inventory. But in the theater building and on the tickets, the seats are arranged in rows of (k) seats and referenced by the pair (row_nbr, seat_within_row_nbr).

Post a Comment

Celko on SQL: Auxiliary Tables vs. Declarative Coding

Auxiliary tables are not only portable across SQL environments and adaptable to external software, they're often a faster, better choice than SQL with computations. And as chips and hardware get faster and cheaper, the auxiliary table approach will make even more sense.

Post a Comment

And the 'Email Validation' SQL Puzzle Winner Is...

The winner of last week's 'Email Address Validation' SQL puzzle is "Guest" (see comments), because he/she bothered to do the research and come up with an answer that is generic enough to port to any SQL dialect with a SIMILAR TO or a regexp() function. So, "Guest" please email me with your snail mail address (and some attempt to validate your SQL mastery/identity) and I'll send you one of my books. Here's my answer to last week's puzzle...

Post a Comment

Celko's Email-Address-Validation SQL Puzzle

You've probably noticed that many Web sites use the customer's email addresses as an identifier. We have all received messages something like this: "Thanks for signing up for 'The Leech Farmer's Monthly' email newsletter! We are sending you a confirmation at your email address with your temporary password." How many ways can you write CHECK() column constraint to validate an email address?

Post a Comment

Celko's 'Can't Be Your Own Supervisor' SQL Puzzle

A small database has the following business rules: 1) Every person in the database is uniquely defined by a single key, their user_id; 2) Everyone is assigned a job category, call them 'A', 'B' and 'X'; 3) Everyone in job category 'X' has a supervisor who must be in either job category 'A' or job category 'B'; 4) Nobody can be their own supervisor. One proposal was to divide job category 'X' into two, call them 'XA' and 'XB' respectively. All the 'XA' people would have 'A' supervisors, and all

Post a Comment

Cooking an old puzzle

I just got an email about Puzzle #11 in my old book SQL PUZZLES & ANSWER from Rainer Gemulla at TU Dresden, Fak. Informatik, Institut SyA, in Dresden, Germany. It is a very nice cook and it is embarassing to see how needlessly complex the other answers were:

Post a Comment

More on streaming databases

There is a good article on streaming databases with lots of product names and stuff suitable for googling inthe current issue of INTELLIGENT ENTERPRISE.

Post a Comment

An Old Celko Puzzle

If you go over to, you will find a letter to the editor from someone named PV about an old column of mine. Here is the jist of it: Back in June of 1996, Jack Wells submitted this SQL problem to my SQL FOR SMARTIES column.

Post a Comment

Hello everyone!

INTELLIGENT ENTERPRISE once more changed format at the end of last year and my long-time column went away. However CMP asked me if I would like to do a blog on SQL, databases and the other things that interests me.

Post a Comment
Register for InformationWeek Newsletters
White Papers
Current Issue
Increasing IT Agility and Speed To Drive Business Growth
Learn about the steps you'll need to take to transform your IT operation and culture into an agile organization that supports business-driving initiatives.
Twitter Feed
InformationWeek Radio
Sponsored Live Streaming Video
Everything You've Been Told About Mobility Is Wrong
Attend this video symposium with Sean Wisdom, Global Director of Mobility Solutions, and learn about how you can harness powerful new products to mobilize your business potential.