MySQL Delete From Multiple Tables in One Query
X

Congrats, You are Subscribed to Receive Updates.

MySQL Delete From Multiple Tables in One Query


MySQL Delete From Multiple Tables in One Query. We always used to connect more than two tables with grouping information’s. like user credentials on one table and his posts and relevant information’s on other table. When we need to delete a user, we don’t need that data to keep in other tables. so we need to delete those data’s in other tables as well.  We may have the following ways to remove those details from different tables.

  1. Multiple Delete queries
  2. Delete with inner join
  3. Delete with left join

Multiple Delete Queries :

We can use multiple delete queries together to delete in deferent tables.

begin transaction

DELETE FROM users WHERE id=2

DELETE FROM employee WHERE user_id=2

DELETE FROM persons WHERE user_id=2

commit transaction

 Delete With inner Join:

Delete multiple records with help of join query.

DELETE users, employee, person FROM users INNER JOIN employee INNER JOIN WHERE users.id=employee.user_id AND employee.user_id= person.user_id

 Delete with Left Join:

Left join is also one of easiest way to delete all together.

DELETE users, employee, person FROM users LEFT JOIN employee ON users.user_id=employee.id WHERE employee.user_id=person.user_id;

I hope this one help you to delete multiple table data’s.

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts