In some situations, where the data to be deleted are known only after combining databases with JOIN clause, the DELETE is combined with JOIN. It is always good practice to use SELECT data and view it, before deleting it. Syntax for joining two tables and deleting the rows in it is:

Syntax

DELETE FROM TABLE1, TABLE2 USING TABLE1 INNER JOIN TABLE2 ON TABLE1.col_id = TABLE2.col_id WHERE condition;

Here the rows from the tables listed before 'USING' is deleted, i.e. rows which satisfies the condition in TABLE1 and TABLE2 are deleted.

Consider the example below where medicationsbrands and medicationsdosages are two tables. The rows where brandID of medicationsbrands is equal to brandID of medicationsdosages and their value is equal to 101 are selected and deleted from both the tables.

DELETE FROM medicationsbrands, medicationsdosages USING medicationsbrands 

INNER JOIN medicationsdosages ON 

medicationsbrands.BrandID=medicationsdosages.BrandID WHERE 

medicationsbrands.BrandID=101;