MySQL – Using DISTINCT and MAX in the same query

  Kiến thức lập trình

I have this type of structure in my MySQL database:

| BOH_ThreadId | BOH_Date   |
|--------------|------------|
| Banana       | 2024-04-23 |
| Banana       | 2024-04-24 |
| Banana       | 2024-04-25 |
| Apple        | 2024-04-21 |
| Apple        | 2024-04-22 |
| Apple        | 2024-04-25 |

How can I get only the DISTINCT BOH_ThreadId associated with the MAX BOH_Date ?

I tried this, but it returned me only one row:

SELECT DISTINCT BOH_ThreadId, MAX(BOH_Date) AS Latest_Date FROM table

Thanks.

LEAVE A COMMENT