October 2022
Intermediate to advanced
380 pages
9h 35m
English
The root cause of this antipattern is simple, and it reveals a common misconception that many programmers have about how grouping queries work in SQL.
The rows in each group are those rows with the same value in the column or columns you name after GROUP BY. For example, in the following query, there is one row group for each distinct value in product_id.
| | SELECT product_id, MAX(date_reported) AS latest |
| | FROM Bugs JOIN BugsProducts USING (bug_id) |
| | GROUP BY product_id; |
Every column in the select-list of a query must have a single value row per row group. This is called the Single-Value Rule. Columns named in the GROUP BY clause are guaranteed ...
Read now
Unlock full access