Efficient latest record query with Postgresql

前端 未结 5 920
深忆病人
深忆病人 2020-12-25 09:59

I need to do a big query, but I only want the latest records.

For a single entry I would probably do something like

SELECT * FROM table WHERE id = ?          


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 10:32

    what do you think about this?

    select * from (
       SELECT a.*, row_number() over (partition by a.id order by date desc) r 
       FROM table a where ID IN $LIST 
    )
    WHERE r=1
    

    i used it a lot on the past

提交回复
热议问题