Efficient query to get last row group by multiple columns
The simplest way in Postgres is with DISTINCT ON:

SELECT DISTINCT ON (1,2,3,4)
       sp.game_id, sportsbook_id, spread_type, spread_duration, game_update_count
FROM   spreads sp
LEFT   JOIN schedule sch USING (game_id)
WHERE  date &gt;= '2012-01-01'
AND    date &lt;= '2012-01-02'
ORDER  BY 4,3,2,1, game_update_count DESC;


Details:


Select first row in each GROUP BY group?


The numbers are just syntax shorthand referring to the ordinal position of SELECT items.

If game_update_count can be NULL, you'll want game_update_count DESC NULLS LAST.


PostgreSQL sort by datetime asc, null first?