Basically, I have two tables that have a 1 to 1 relation.
When I delete a row from subset_panel_options I also want to delete the related row in subset_panel_options_list
Here is some of structure for the two tables. There is no need to show the full table.
[subset_panel_options]
->id
->subset_panel_id[subset_panel_options_list]
->id
->subset_panel_options_id
DELETE subset_panel_options, subset_panel_options_list
FROM subset_panel_options
JOIN subset_panel_options_list
WHERE subset_panel_options.id = subset_panel_options_list.subset_panel_options_id
AND subset_panel_id = $subsetPanelId
Yes, it can:
Using
LEFT JOINyou ensure you are deleting from “subset_panel_options” even if there is no corresponding match in the subset_panel_options_list table.You may also want use referential integrity features available in InnoDB engine. In this case, you need to define
subset_panel_options_idas a FK (foreign key) in thesubset_panel_options_listtable, and an “ON DELETE CASCADE” constraint on it, meaning that when rows atsubset_panel_optionsare deleted, the “orphan” rows insubset_panel_options_listshould be immediately deleted too.