Search Postgresql Archives

Embarassing GROUP question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux