Subject Re: First function
Author Fabrice Aeschbacher
Robert,

One possible solution is:

create view max_priority (groupf, priority) as
select groupf, max(priority)
from table
group by groupf

and then:

select
groupf, string
from
table t, max_priority mp
where
mp.groupf=t.groupf and
mp.priority=t.priority

Also create appropriate indexes.

Regards,
Fabrice

--- In ib-support@y..., "Robert Munro" <rjmunro-egroups@i...> wrote:
> 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