I have 3 tables:
AAA with the columns:
id | text
BBB with the columns (aaa_id is a foreign key => id from the previous table – AAA):
id | text | aaa_id
and CCC with the columns (bbb_id is a foreign key => id from the previous table – BBB):
id | text | bbb_id
Now when I delete a record from the table AAA I want to delete all the records from the table BBB which are aaa_id = AAA.id and also delete all the records from the table CCC which are connected to the records I’d like to delete from BBB (so they have bbb_id equal to BBB.id of the records which are aaa_id equal to AAA.id).
I’ve tried to user inner join but I had no luck. Meanwhile, I select all the records with PHP and delete them separately.
The tables are MyISAM.
You could use INNER JOIN as well, if there’s always child records in each table. Or you can set up ON DELETE CASCADE in your foreign key constraints.