"selecting most recent as part of group by (or other solution ...)" Code Answer

9

Untested, but you should be able to handle this with a join:

SELECT
    fullEvent.id,
    fullEvent.username,
    fullEvent.source,
    fullEvent.topic
FROM
    events fullEvent JOIN
    (
        SELECT max(id) as MAX_ID, username, source
        FROM   events
        GROUP BY source, username
    ) maxEvent ON maxEvent.MAX_ID = fullEvent.id
ORDER BY fullEvent.id desc;
By Piyush on April 29 2022

Answers related to “selecting most recent as part of group by (or other solution ...)”

Only authorized users can answer the Search term. Please sign in first, or register a free account.