When a parent category(e.g., Architecture, Art and Culture) is dropped from the database, I want all subcategories under the parent category to be dropped from the database. I don't know how to write a query for this.
I am using PHP and MySQL database, the category and subcategory are two separate tables, the snapshots of the tables are given below.
Category Table
Subcategory Table
DELETE c, s FROM category AS c JOIN subcategory AS s ON c.cat_id = s.parent_id
. Another tip I could add is merge the two tables cat_id, parent_id, cat_name, but will require some joining sql – Mujnoi Gyula Tamas