I have a single table as follows:
+---+----------+----------+---------+---------+
+ID + FIELD 1 + FIELD 2 + FIELD 3 + FIELD 4 +
+---+----------+----------+---------+---------+
+ 1 + AAA + 1234 + ABC + Y +
+ 2 + AAA + 1234 + DEF + +
+ 3 + AAA + 1234 + GHI + +
+ 4 + BBB + 1234 + ABC + +
+ 5 + CCC + 1234 + JKL + +
+---+----------+----------+---------+---------+
I have a process running that may set FIELD4 to “Y” and then a second process that checks for the value of ‘Y’ in a FIELD4.
I need to write a query (or queries probably) that will delete the record where FIELD4 = ‘Y’, but then also delete all other records where FIELD1 is of the same value to that of the originally deleted record.
For the record, FIELD4 will eventually become a check box and the MySQL required will be called from within a PHP script. With this in mind, if the solution involves PHP this would not be an issue.
I’ve had a good search around PHP and MySQL sites and forums, but can’t locate a One to Many deletion. Any ideas out there?
Try with following query: