When you have two competing theories that make exactly the same predictions, the simpler one is the better.
October 2022
Intermediate to advanced
380 pages
9h 35m
English
Content preview from SQL Antipatterns, Volume 1
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial



Solution: Divide and Conquer
The quote at the beginning of this chapter is similar to the law of parsimony:
The Law of Parsimony
What this means to SQL is that when you have a choice between two queries that produce the same result set, choose the simpler one. We should keep this in mind when straightening out instances of this antipattern.
One Step at a Time
If you can’t see a logical join condition between the tables involved in an unintended Cartesian product, that could be because there simply is no such condition. To avoid the Cartesian product, you have to split up a Spaghetti Query into several simpler queries.
In the simple ...