Make your queries consistent

by Charles Miller on April 8, 2003

Unless there is a very good reason for it not to, software should behave predictably. Predictable software is easier to test, predictable APIs are easier to interface with, predictable programs are easier to use.

One tenet of predictability is that when you make identical queries against identical sets of data, the results should also be identical. In queries that return multiple responses, this includes the order in which the data is returned.

For example (and this is what prompted the post), always put sufficient ORDER BY clauses in your SQL queries that the data is assured to come back in the same order every time. If the ordering turns out to be a performance problem, it's time to remove them. Until then, get into the habit of putting them there by default.

Previously: Mail.app problem solved?

Next: A good host is hard to find