Hi there. I have such SQL to fetch latest records for each group:
SELECT tp.id,tp.team_id,tp.player_id FROM (
        SELECT tps.team_id,tps.player_id,MAX(tps.dt_from)
        AS dt_from
        FROM team_players tps
        GROUP BY tps.team_id,tps.player_id
) AS tps
JOIN team_players tp ON(tp.dt_from=tps.dt_from AND
tp.team_id=tps.team_id AND tp.player_id=tps.player_id)

where dt_from is TIMESTAMP.
Is it possible to get the same result without using Raw SQL? thanks

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to