0

I am not even really sure how to search for this type of question, let alone tackle solving it. Please direct me if there are keywords to use for developing such a query, and thus searching for solutions already provided.

I have two tables - threads and comments.

thread table

thread_id title text
1 Foobar foo
2 Barfoo bar

comment table

comment_id date text thread_id
1 1 lorem 1
2 2 ipsem 1
3 3 gypsum 2
4 4 tippy 2

Use - I want to show a sidebar on the front page of a site showing the latest comments. But I only want to show the most recent comment per each thread. Meaning, I want the result to look like this:

result

comment_id text thread_id
4 tippy 2
2 ipsem 1

Can anyone kindly point me to how I might go about searching for help / keywords on this type of query and/or direct help in what mysql syntax is necessary to do this kind of query please?

Thank you

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Appl3s
  • 177
  • 3
  • 11
  • 1
    Something like this? Search terms I used were "mysql join limit max" https://stackoverflow.com/questions/29177721/mysql-join-table-based-on-maxdate-in-main-table-and-maxid-in-joined-table-w – MacAnthony May 25 '21 at 19:38
  • 1
    This type of question is asked frequently. Usually they are tagged [tag:greatest-n-per-group]. There are many good answers posted. – Bill Karwin May 25 '21 at 20:28

0 Answers0