Subject Re: [firebird-support] delete min
Author Kjell Rilbe
Alejandro Garcia wrote:

> There are many dates for each patient and I need to select the minimun
> date for each patient. This SQL works fine:
>
> SELECT T.NUMPAT,T.TREATMENT,T.DATE
> FROM MYTABLE T
> WHERE
> T.DATE=
> (SELECT MIN(Q.DATE) FROM
> MYTABLE Q WHERE T.NUMPAT = Q.NUMPAT )
> order by T.NUMPAT
>
> By now I need to delete that minimun date for each patient, and simply
> change the first SELECT for a DELETE is not working... how could I?
> Sorry for this so simple question...

I would have expected this to work:
DELETE
FROM MYTABLE T
WHERE
T.DATE=
(SELECT MIN(Q.DATE) FROM
MYTABLE Q WHERE T.NUMPAT = Q.NUMPAT )

Note that the order by has been removed.

Why doesn't it work? What error do you get?

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64