I have comments
table. Structure like this
id parent_id user_id comment
-- --------- ------- -------
I want to delete records where have incorrect related values.
For delete records where user_id is invalid value I use this query
DELETE FROM `comments` WHERE `user_id` NOT IN (SELECT `id` FROM `users`)
but when I try to delete records where parent_id is invalid data I use this query
DELETE FROM `comments` WHERE `parent_id` NOT IN (SELECT `id` FROM `comments`)
I get this error
Error Code: 1093 You can't specify target table 'comments' for update in FROM clause