Hello.
I am writing in PHP, MySQL database.
There is a category entity (table categories, id and name fields), there is a product entity (products table, id and name fields) and they are connected by many to many (product_category table, id, category_id and product_id fields).
I have a task that sounds simple enough: "You must remove all empty categories."
I use the Laravel framework and the simplest thing that gets into my head is to request all categories with products (via communication) and then in a loop to delete each category that does not contain products.
But I can’t figure out how to do this in one request. Select the condition for selecting empty categories and delete all entries in the categories table that fit this condition.