How to select the most recent set of dated records from a mysql table

后端 未结 7 1613
我在风中等你
我在风中等你 2020-11-29 01:00

I am storing the response to various rpc calls in a mysql table with the following fields:

Table: rpc_responses

timestamp   (date)
method      (varchar)
id          


        
7条回答
  •  暖寄归人
    2020-11-29 01:19

    Self answered, but I'm not sure that it will be an efficient enough solution as the table grows:

    SELECT timestamp,method,id,response FROM rpc_responses 
    INNER JOIN
    (SELECT max(timestamp),method,id FROM rpc_responses GROUP BY method,id) latest
    USING (timestamp,method,id);
    

提交回复
热议问题