Search code examples
mysqlsql-delete

MySQL Delete Records from 2 Tables


I'm looking to delete information in two different tables in 1 query, based on an ID.

I've tried several solutions on here to accomplish this task but still have not accomplished what I'm trying to do.

Table 1 - Content

---------- ---------
 ContentID | Content
--------------------

Table 2 - Votes

---------------------------
 VoteID | ContentID | Vote 
---------------------------

I want to delete the content row based on its ID and any or all votes (there could be 0 vote records). I do NOT want to use transactions, cascading deletes, or use 2 different queries.

What is best here - a LEFT JOIN? INNER JOIN?

Any help here would be greatly appreciated.


Solution

  • DELETE Content, Votes
    FROM Content
    LEFT JOIN Votes
    ON Votes.ContentID = Content.ContentID
    WHERE Content.ContentID = ?