I have these three working queries:
SELECT a, time, b, c
FROM table_first
WHERE created_at >= timestamp '2022-02-13 00:00:00'
AND a = 'LK0601'
ORDER BY time DESC
LIMIT 1;
SELECT a, time, b, c
FROM table_first
WHERE created_at >= timestamp '2022-02-13 00:00:00'
AND a = 'DT9834'
ORDER BY time DESC
LIMIT 1;
SELECT a, time, b, c
FROM table_first
WHERE created_at >= timestamp '2022-02-13 00:00:00'
AND a = 'LM3526'
ORDER BY time DESC
LIMIT 1;
In these queries, I get the latest entry for the different values of a.
How can I merge them into one query?
So that it becomes something like the following:
SELECT a, time, b, c
FROM table_first
WHERE created_at >= timestamp '2022-02-13 00:00:00'
AND a IN ('LM3526','DT9834','LK0601')
GROUP BY a
ORDER BY time DESC
LIMIT 1;
From the above query, I want to get the latest rows for all the different values of a
.
I am using the PostgreSQL database.