June 2010
Intermediate to advanced
328 pages
7h 51m
English
The sections that follow describe several ways you can resolve this antipattern and write unambiguous queries.
The most straightforward solution is to eliminate ambiguous columns from the query.
| Groups/anti/groupbyproduct.sql | |
| | SELECT product_id, MAX(date_reported) AS latest |
| | FROM Bugs JOIN BugsProducts USING (bug_id) |
| | GROUP BY product_id; |
The query reveals the date of the latest bug per product, even though it doesn’t report the bug_id corresponding to that latest bug. Sometimes this is enough, so don’t overlook a simple solution.
A correlated subquery contains a reference to the outer query and so produces different results ...
Read now
Unlock full access