"Arnaud Berger" wrote...
>> i have four tables T1, T2, T3 and T4 related to each other
>> in a one to many relation (one in T1 to many in T2. one in
>> T2 to many in T3, and one in T3 to many in T4).
>>
>> how would i delete all rows in T4 that are related
>> (or trace back) to a specific record in T1.
> Not sure this may work, but give it a try :
>
> delete from T4 where id in
> ( select id from T4 where T3_ID in
> ((select id from T3 where T2_ID in
> (select id from T2 where T1_ID="yourId"))))
Not necessary with that many levels in the subqueries...
delete from T4
where T3_ID in
( select T3.ID
from T3, T2
where T3.T2_ID = T2.ID
and T2.T1_ID = ? )
I've put a question mark where you insert the id for T1 as a parameter in a
PreparedStatement.
// Bjorn A
hilz - 25 May 2005 14:25 GMT
>>Not sure this may work, but give it a try :
>>
[quoted text clipped - 11 lines]
> where T3.T2_ID = T2.ID
> and T2.T1_ID = ? )
Thanks to you Bjorn and Arnaud. That was pretty quick answer.
I like Bjorn's way since i might have more levels!
thank you very much
hilz
Arnaud Berger - 26 May 2005 07:28 GMT
Quite right, this looks a bit cleaner ;)
Regards,
Arnaud
> "Arnaud Berger" wrote...
>
[quoted text clipped - 25 lines]
>
> // Bjorn A