# SQL Antipatterns, Volume 1: join error (page 176)

**URL:** <https://forum.devtalk.com/t/sql-antipatterns-volume-1-join-error-page-176/141945>\
**Category:** PragProg Customers\
**Tags:** book-sql-antipatterns-volume-1, errata\
**Created:** [1 February 2024 02:39 UTC](https://forum.devtalk.com/t/sql-antipatterns-volume-1-join-error-page-176/141945 "2024-02-01T02:39:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![billkarwin](https://forum.devtalk.com/user_avatar/forum.devtalk.com/billkarwin/32/3276_2.png) [@billkarwin](https://forum.devtalk.com/u/billkarwin)\
**Post date:** [2 February 2024 03:50 UTC](https://forum.devtalk.com/t/sql-antipatterns-volume-1-join-error-page-176/141945/2 "2024-02-02T03:50:58Z")

</div>

Thanks for the feedback blabla\_bingo, I see the error. Yes, this is a mistake.

Here’s a working query for that example:

```auto

SELECT m.product_id, m.latest, MAX(b1.bug_id) AS latest_bug_id
FROM Bugs b1
JOIN BugsProducts p USING (bug_id)
JOIN (
  SELECT product_id, MAX(date_reported) AS latest
   FROM Bugs b2 JOIN BugsProducts USING (bug_id)
   GROUP BY product_id
) m
  ON (b1.date_reported = m.latest AND p.product_id = m.product_id)
GROUP BY m.product_id, m.latest;

```

I’ll try to get this correction into the next printing of the book.

---

_[View the full topic](https://forum.devtalk.com/t/sql-antipatterns-volume-1-join-error-page-176/141945)._
