How can I write a query that will give me all the rows of a particular id that have the latest date filtered by another column?
For example. I want all records that have the latest date where name equals Lily and Al
From this table:
| id | date | name |
|---|---|---|
| 111 | 2022-08-24 20:56:54 | Lily |
| 111 | 2022-08-24 20:56:54 | Lily |
| 111 | 2022-08-24 20:56:54 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 333 | 2022-08-26 06:29:59 | Stan |
| 333 | 2022-08-26 06:29:59 | Stan |
| 333 | 2022-08-26 06:29:59 | Stan |
| 333 | 2022-08-26 06:29:59 | Stan |
| 444 | 2022-09-08 18:17:11 | Al |
| 444 | 2022-09-08 18:17:11 | Al |
| 444 | 2022-09-08 18:17:11 | Al |
The result of the query should be:
| id | date | name |
|---|---|---|
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 222 | 2022-08-30 17:47:16 | Lily |
| 444 | 2022-09-08 18:17:11 | Al |
| 444 | 2022-09-08 18:17:11 | Al |
| 444 | 2022-09-08 18:17:11 | Al |
Thanks!