Hi all,

I'm a recent MySQL convert, and I am having some difficulty with syntax on grouping a table by a foreign key and returning only the newest entry that matches. In MySQL, you can do something like

event_log
------------
id
event_type
event_date
meaningful_data


SELECT
        meaningful_data,
        event_type,
        event_date
FROM
        event_log
GROUP BY
        event_type
ORDER BY
        event_date DESC



And this would return back the most recent event and meaningful data for each event type. When I try this in postgres, I get errors about either grouping by id or using id in an aggregate function. I am afraid if I use it in an aggregate function, it will disrupt the sort order I am attempting, and if I group by it, I no longer get the most recent data for each event type, but I get every event. How would I accomplish this is postresql? Is there some aggregate functions that help with this, or should I be trying a different method altogether? Grouping feels pretty different, and I suspect closer to standards, in postgres. Unfortunately, my mind works (for the short term) in mysql. Will someone please give me some pointers?

Thanks!
Corey

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to