|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Delete min
Hi! I have a patient's table with 3 fields:
NUMPAT is the number of the patient TREATMENT is a treatment code DATE a date 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.TREATMEN T,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... |
|
#2
|
||||
|
||||
|
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#3
|
|||
|
|||
|
Code:
DELETE FROM FROM MYTABLE WHERE "DATE" = (SELECT MIN(Q.DATE) FROM MYTABLE Q WHERE MYTABLE.NUMPAT = Q.NUMPAT) But I strongly recommend not to use a reserved word (DATE) as a column name! |
|
#4
|
|||
|
|||
|
Yes, something like this should work, but does not, I don't know why, it deletes the whole table
DELETE FROM MYTABLE p WHERE p.DATA = ( SELECT MIN(a.DATA) FROM MYTABLE a WHERE a.C_HISTORIA = p.C_HISTORIA ) |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Delete min |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|