[ale] delete rows in mysql

Chris Fowler cfowler at outpostsentinel.com
Wed May 5 09:42:55 EDT 2010


I want to delete rows in a main table that are mapped in a 2nd table.

I have a table called `trigger`.  It lists all the possible triggers.
There is a group table called `trigger_group`.
I map triggers to a trigger_group via the trigger_group_map table.

I want to delete not only a trigger_group but also the triggers that are
mapped to that group

I've tried this

delete from trigger where trigger_id=(select trigger_id from
trigger_group_map where trigger_group_id=3)

That gives me a result of 0 rows so there is obviously a better way to
do this.  I can easily write a perl loop that will the following:

select trigger_id from trigger_group_map where trigger_group_id=3
for each
  delete from trigger where trigger_id=X
  delete from trigger_group_map where trigger_id=X
done


I've got a new list of triggers and I want to delete not only the
mappings but the old triggers from trigger table before I import these.

Chris



More information about the Ale mailing list