0

I could finally solve the DELETE CASCADE. for these tables.

http://subefotos.com/ver/?a6f811bfb78e9aa78ffe43adb1f3cf5do.png

Now... I need delete all row on AlergiaTipo when these seems related to a alergiagrupo on the table ALERGIA. I make this statement.

delete from alergiatipo where ID in (select alergiatipo.ID from alergia,alergiatipo where
alergia.AlergiaTipo_ID = alergiatipo.iD and alergia.ID in (select alergia.ID from 
alergia,alergiagrupo where alergia.AlergiaGrupo_ID = alergiagrupo.ID AND 
alergiagrupo.ID = '2'));

but return me this error

Error Code: 1093. You can't specify target table 'alergiatipo' for update in FROM clause

1 Answer 1

1

This is your delete with proper explicit join syntax:

delete from alergiatipo
    where ID in (select alergiatipo.ID
                 from alergia join
                      alergiatipo
                      on alergia.AlergiaTipo_ID = alergiatipo.iD
                 where alergia.ID in (select alergia.ID 
                                      from alergia join
                                           alergiagrupo 
                                           on alergia.AlergiaGrupo_ID = alergiagrupo.ID 
                                      where alergiagrupo.ID = '2'
                                     )
               );

In MySQL, you cannot specify the table being deleted elsewhere in an update or delete. Plus, your delete is rather overdone. I think you just want the following:

delete alt
    from alergiatipo alt join
         alergia a
         on a.AlergiaTipo_ID = alt.iD join
         alergiagrupo ag
         on a.AlergiaGrupo_ID = ag.ID
    where ag.ID = 2;

I also removed the single quotes around 2. I'm guessing the column is an integer, so you should use an integer constant rather than a string constant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.