October 2022
Intermediate to advanced
380 pages
9h 35m
English
Most programmers who learn SQL get to the stage of using GROUP BY in a query, applying some aggregate function to groups of rows, and getting a result with one row per group. This is a powerful feature that makes it easy to get a wide variety of complex reports using relatively little code.
For example, a query to get the latest bug reported for each product in the bugs database looks like this:
| | SELECT product_id, MAX(date_reported) AS latest |
| | FROM Bugs JOIN BugsProducts USING (bug_id) |
| | GROUP BY product_id; |
A natural extension to this query is to request the ID of the specific bug with the latest date reported:
| |
Read now
Unlock full access