Thursday, 17 May 2012

Multi Delete Query Using LEFT JOIN in Mysql

DELETE a.*, b.* FROM invoice_details a LEFT JOIN invoices b ON a.invoiceID=b.invoiceID WHERE a.rollover_by>0;

It will delete all the records from invoice_details and matching or available record from invoices(In this table record may be present or not).

Note: Have you notice the table name a.*, b.* used in selecting table for deletion. Yes you have to keep it in mind that you can use only alias table name for selection otherwise mysql will throw the error that "Table name does not exist".

No comments:

Post a Comment