Deleting record

Hello,

I want to make delete post query and when I delete specific post I want to delete comments too. I’ve made query and it deletes posts only if that post have comments.

DELETE `p`, `c`
FROM `posts` AS `p`
INNER JOIN `comments` AS `c`
ON `p`.`id` = `c`.`post_id`
WHERE `p`.`id` = ?

How I can make query that deletes post event if there is no comments in it?

Solved by using LEFT OUTER JOIN.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.