Read more

Delete from joined MySQL tables

Henning Koch
September 23, 2010Software engineer at makandra GmbH

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.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Henning Koch to makandra dev (2010-09-23 23:15)