So I have this app, where users create expense reports. Each report has many receipts, and I need to be able to let users delete their reports with the associated receipts. I have a sql statement now that does just that but it only works IF there the report has receipts, so if it has no receipts the report doesnt get deleted:
mysql_query("DELETE expense_general, expense_receipts FROM expense_general JOIN expense_receipts ON expense_general.id = expense_receipts.expense_general_id WHERE expense_general.id = {$expenseID}");
$expenseID is the report record ID number. so I do I get the statement to delete the reports with no receipts?
Use a
LEFT JOINquery, i.e.this will match on the
expense_generaltable, regardless of whether there is anything linked in theexpense_receiptstable.