I want to get latest records of the table with some settings_ids.
id | settings_id | added_date |
---|---|---|
1 | 7 | 2022-08-23 01:44:24 |
2 | 9 | 2022-08-23 01:44:24 |
3 | 11 | 2022-08-23 01:44:24 |
4 | 7 | 2022-08-25 01:44:24 |
5 | 9 | 2022-08-25 01:44:24 |
6 | 11 | 2022-08-25 01:44:24 |
7 | 7 | 2022-08-26 01:44:24 |
8 | 9 | 2022-08-26 01:44:24 |
9 | 11 | 2022-08-26 01:44:24 |
SELECT id, settings_id, MAX(added_date)
FROM data_rows
WHERE settings_id IN (7,9,11)
GROUP BY settings_id;
Expected Result
id | settings_id | added_date |
---|---|---|
7 | 7 | 2022-08-26 01:44:24 |
8 | 9 | 2022-08-26 01:44:24 |
9 | 11 | 2022-08-26 01:44:24 |
I am getting the result I want but the thing is it taking more than a minute to get the data.
Is there a way to reduce the time taken by this query?
Thanks