MySQL Delete From Inner Join

Profile picture for user arilio666

What if inner join can also be used as a delete query for removing rows from one table matching with a standard column from both tables.

Syntax

DELETE target tables  
FROM    table1    
INNER JOIN table2  
ON table1.commonColumn= table2.commonColumn  
WHERE condition  
  • Using this syntax, we can delete rows from more than one table.

Example

Let us take two tables, WorkEmployee and EmpJoinDetails.

delete mysql inner join

delete with inner join mysql

DELETE WorkEmployee, EmpJoinDetails FROM WorkEmployee  
INNER JOIN EmpJoinDetails ON WorkEmployee.cID=EmpJoinDetails.cID   
WHERE WorkEmployee.cID = 104;  

mysql delete inner join

delete con inner join mysql

  • We can see that using this query using the delete query in join matching the corresponding columns can delete that.
  • Likewise, we can see that the cID from the matching specified ids has been removed.
Tags