I want to Make a SQL Query that returns the newest Entry for each bot_id.
My current request looks like this, but it ALWAYS returns the first Entry. DESC & ASC don't make any difference:
SELECT bot_id, id
FROM t_request_history
GROUP BY bot_id
ORDER BY request_time DESC
The Tables looks like this:
t_request_history
| id | bot_id | request | response | error | request_time |
|---|---|---|---|---|---|
| 1 | usr_e74ae42b-080c-48e0-9e6c | a | a | 0 | 2021-09-16 23:37:10 |
| 2 | usr_e74ae42b-080c-48e0-9e6c | a | a | 1 | 2021-09-16 23:37:35 |
| 3 | usr_e74ae42b-080c-48e0-9e6c | a | a | 1 | 2021-09-16 23:43:20 |
| 4 | delete | 1 | 1 | 1 | 2021-09-16 23:44:21 |
| 5 | delete | 1 | 1 | 0 | 2021-09-16 23:44:32 |
| 6 | delete | 1 | 1 | 0 | 2021-09-16 23:44:41 |
Wanted Result
| bot_id | id |
|---|---|
| delete | 6 |
| usr_e74ae42b-080c-48e0-9e6c | 3 |
Actual Result
| bot_id | id |
|---|---|
| delete | 4 |
| usr_e74ae42b-080c-48e0-9e6c | 1 |
Is there any way to make this query work?