Subject | First function |
---|---|
Author | Robert Munro |
Post date | 2001-07-17T11:30:32Z |
Is there a way to pick the first record in a GROUP BY, like the First
function in access?
I have, in effect a table:
id | GroupF | String | Priority
---------------------------------
1 | 1 | Hello | 10
2 | 1 | Hi | 8
3 | 2 | Bye | 9
4 | 2 | Goodbye | 12
I want to pick the strings with the highest priority in each group,
i.e.
GroupF | String
-----------------
1 | Hello
2 | Goodbye
I tried:
SELECT GroupF, Min(String) FROM table GROUP BY GroupF
HAVING Priority = Max(Priority);
and it didn't give an error, which was a surprise, but it didn't work
either.
In Access, I thought I could do:
SELECT GroupF, First(String) FROM table ORDER BY Priority DESC
GROUP BY GroupF;
but actually, on trying it out, it seems I can't do that, either.
Any ideas?
Robert Munro
function in access?
I have, in effect a table:
id | GroupF | String | Priority
---------------------------------
1 | 1 | Hello | 10
2 | 1 | Hi | 8
3 | 2 | Bye | 9
4 | 2 | Goodbye | 12
I want to pick the strings with the highest priority in each group,
i.e.
GroupF | String
-----------------
1 | Hello
2 | Goodbye
I tried:
SELECT GroupF, Min(String) FROM table GROUP BY GroupF
HAVING Priority = Max(Priority);
and it didn't give an error, which was a surprise, but it didn't work
either.
In Access, I thought I could do:
SELECT GroupF, First(String) FROM table ORDER BY Priority DESC
GROUP BY GroupF;
but actually, on trying it out, it seems I can't do that, either.
Any ideas?
Robert Munro