Antipattern: Solve a Complex Problem in One Step
SQL is a very expressive language—you can accomplish a lot in a single query or statement. But that doesn’t mean it’s mandatory or even a good idea to aim to solve every problem in one line of code. Do you have this habit with any other programming language you use? Probably not.
Unintended Products
One common consequence of producing all your results in one query is a Cartesian product. This happens when two of the tables in the query have no condition restricting their relationship. Without such a restriction, the join of two tables pairs each row in the first table to every row in the other table. Each such pairing becomes a row of the result set, and you end up with many more rows than you ...
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,
and much more.
Read now
Unlock full access