MySQL - 连接表,仅检索Max ID

jwB*_*ide 10 sql max greatest-n-per-group

我已经在其他帖子上看到了类似的解决方案,但我一直在将问题应用于我的具体问题.

这是我最初的加入:

SELECT service_note_task, comment_id, comment FROM service_note_task LEFT JOIN service_note_task_comments ON service_note_task.service_note_task_id = service_note_task_comments.service_note_task_id;  
Run Code Online (Sandbox Code Playgroud)

结果如下:

+-----------------------------+------------+--------------+
| service_note_task           | comment_id | comment      |
+-----------------------------+------------+--------------+
| This is service note task 3 |         25 | Comment      |
| This is service note task 3 |         26 | Comment Blah |
| This is service note task 3 |         36 | aaa          |
| This is service note task 2 |         13 | Awesome comm |
| This is service note task 1 |         12 | Cool Comm    |
+-----------------------------+------------+--------------+
Run Code Online (Sandbox Code Playgroud)

但对于每个service_note_task,我真的只需要一行代表具有最高comment_id的注释,如下所示:

+-----------------------------+------------+--------------+
| service_note_task           | comment_id | comment      |
+-----------------------------+------------+--------------+
| This is service note task 3 |         36 | aaa          |
| This is service note task 2 |         13 | Awesome comm |
| This is service note task 1 |         12 | Cool Comm    |
+-----------------------------+------------+--------------+
Run Code Online (Sandbox Code Playgroud)

我想我可以在子选择语句中使用MAX来缩小我想要的结果.我如何将其纳入我的陈述中以获得这些结果?