Use this solution with caution:
it is not guaranteed to work in future versions of mysql
it is not known to work in mariadb 5.5
This can query may perform well, because there are no joins.
SELECT * FROM (
SELECT timestamp, method, id, response
FROM rpc_responses
WHERE 1 # some where clause here
ORDER BY timestamp DESC
) as t1
GROUP BY method
The "group by", collapses the result set on method, and returns only 1 row per method, the most recent one, because of the ORDER BY timestamp DESC in the inner query.
FYI, PostgreSQL has a way of doing this built into the language:
SELECT DISTINCT ON (method) timestamp, method, id, response
FROM rpc_responses
WHERE 1 # some where clause here
ORDER BY method, timestamp DESC
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…