Subject Re: [firebird-support] SELECT MIN
Author Helen Borrie
At 07:12 PM 24/04/2007, you wrote:
>Hi, I have this problem: my table is
>PATIENTID, DATE, DIFF
>
>for each PATIENTID can be many DATE and many DIFF, DIFF is an
>integer and I need for each PATIENTID the MIN DIFF and the DATE of
>the same line where MIN(DIFF) is.
>
> I did this: but it's not working
>
> SELECT PATIENTID,DATE,DIFF FROM T MYTABLE
> WHERE DIFF = (SELECT MIN(DIFF) FROM Q MYTABLE
> WHERE (T.PATIENTID = Q.PATIENTID
> AND T.DATE = Q.DATE )

No, it wouldn't be working. I don't think you quite have the "hang"
of table aliasing yet! ;-)

SELECT
t.PATIENTID,
t.fecha
t.,DIFF
FROM MYTABLE t
WHERE
t.DIFF = (SELECT MIN(q.DIFF) FROM MYTABLE q
WHERE t.PATIENTID = q.PATIENTID
AND t.fecha = q.fecha )

./heLen