MySQL Delete with a LEFT JOIN

A database I was working on had some orphanned records that I was able to see using a LEFT JOIN.

SELECT EventID FROM EventLog e LEFT JOIN CustInfo c USING (CustID) WHERE c.CustID IS NULL;

Deleting those records is a little more complicated that changing the SELECT to DELETE. Specifically you have to tell MySQL what table you want to delete the records from (i.e. Eventlog.*) otherwise it gets confused about what table to delete the records from.

DELETE e.* FROM EventLog e LEFT JOIN CustInfo c USING (CustID) WHERE c.CustID IS NULL;

Information borrowed from ElectricToolbox.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 18.234.236.14
To prevent spam please submit by clicking the kitten: