MySQL Delete Statement With Join
There are a couple of ways to do a mysql. Lets say you want to delete all comments from a blog post named 'sandbox' in your database. Here are several ways of achieving this.
DELETE FROM comments c USING comments c, posts p WHERE c.post_id = p.post_id AND p.title='sandbox'; DELETE comments FROM comments c, posts p WHERE c.post_id = p.post_id AND p.title='sandbox'; DELETE comments FROM comments c JOIN posts p ON c.post_id = p.post_id WHERE p.title='sandbox'; DELETE comments FROM comments c JOIN posts p USING(post_id) WHERE p.title='sandbox';
code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)