Alex,
> which is the highest value of 'sortby' for each value of 'fk'.
>
> I would think that the SQL to achieve this is:
>
> SELECT * FROM test GROUP BY fk HAVING sortby = MAX(sortby);
You need a subselect for this:
SELECT test.*
FROM test, (SELECT max(sortby) as maxsort, fk
"Alex Page" <[EMAIL PROTECTED]> writes:
> I'm trying to write a query that returns the rows containing the
> most recent values for each foreign key.
The best way to do this (on every dimension except portability :-()
is SELECT DISTINCT ON. See the weather-report example in the SELECT
reference
I'm having real trouble with aggregate functions. I have a table which
tracks the value of a field in another table over time - it contains a
foreign key to the row in the other table, the value, and a timestamp to
sort by. I'm trying to write a query that returns the rows containing the
most rece