Subject Re: [firebird-support] Re: How to optimize this query
Author Alexandre Benson Smith
Christian Kaufmann wrote:

>Hi Alexandre,
>
>
>
>>Have you tried this kind of query ?
>>
>>
>
>
>
>>where
>> and R.SWINTIME = (select min(SWINTIME) from t_RESULT where
>>
>>
>T_ATHLETID = A.T_ATHLETID)
>
>
>>order by
>> R.SWIMTIME
>>
>>
>
>If I understand that correctly, only the absolute fastest time of a
>ATHLETE is read. Now the fastest time depends on different other
>fields:
>T_EVENT.STYLEID, T_SESSION.COURSE, T_SESSION.STARTDATE
>
>so I don't think, that this will give correct results.
>
>cu Christian
>
>
Chirstian,

try this one...

select
R.T_RESULTID, min(R.SWIMTIME),
A.LASTNAME, A.FIRSTNAME, A.BIRTHDATE,
S.STARTDATE, M.CITY, M.NATION,
C.CODE
from T_RESULT R
join T_ATHLETE A on A.T_ATHLETEID = R.T_ATHLETEID
join T_AGEGROUP AG on AG.T_AGEGROUPID = R.T_AGEGROUPID
join T_EVENT E on E.T_EVENTID = AG.T_EVENTID
join T_SESSION S on S.T_SESSIONID = E.T_SESSIONID
join T_MEET M on M.T_MEETID = S.T_MEETID
join T_ATHLETEMEET MM on MM.T_MEETID = M.T_MEETID and MM.T_ATHLETEID =
A.T_ATHLETEID
join T_CLUB C on C.T_CLUBID = MM.T_CLUBID

where
E.T_STYLEID = 1 and
A.GENDER = 0
/* and C.T_CLUBID = 56 */
group by
R.T_RESULTID,
A.LASTNAME, A.FIRSTNAME, A.BIRTHDATE,
S.STARTDATE, M.CITY, M.NATION,
C.CODE

see you !

--

Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br