Hi there,
I have a table that has three columns: Category, Timestamp and Value.
What I want is a SQL select that will give me the 5 most recent values of each category. How would I go about and do that?
I tried this:
select
a."Category",
b."Timestamp",
b."Value"
from
(select "Category" from "Table" group by "Category" order by "Category") a,
(select a."Category", c."Timestamp", c."Value" from "Table" c
where c."Category" = a."Category" limit 5) b
Unfortunately, it won't allow it because "subquery in FROM cannot refer to other relations of same query level".
I'm using PostGreSQL 8.3, by the way.
Any help will be appreciated.