How to delete records from multiple table using single sql statement?

Hi Friends,

Today I am going to tell you that how you can delete records from 2 tables by using single query. It is not possible to delete records from multiple table using simple delete query, but you can achieve this by using join in your sql statement. Now I am going to give you a very simple example with two table.
1) Category (id, title)
2) Product (id, title , cat_id)
Note* :- cat_id in Product table is a join key for category.

Now I want to delete all category and their product which id is 2. then our query will be
“DELETE Category , Product FROM Category INNER JOIN Product ON Category .id = Product .cat_id WHERE (Category .id)=’2′”

Cheers 🙂


Share This Post

Recent Articles

Leave a Reply


© 2019 Networkocean. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie