Delete from joined MySQL tables

Updated . Posted . Visible to the public.

When you need to delete rows from a table, and the delete conditions require a joined table, MySQL needs to know which table you want to delete from.

Let's say that Post belongs_to :author. In order to delete all posts from the author named "Eric", write

DELETE posts FROM posts LEFT JOIN authors ON posts.author_id = authors.id WHERE authors.name = 'Eric'

Notice the additional "posts" between DELETE and FROM.

Henning Koch
Last edit
Keywords
multiple, update
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-09-23 21:15)