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.
DELETE Content, Votes
FROM Content
LEFT JOIN Votes
ON Votes.ContentID = Content.ContentID
WHERE Content.ContentID = ?
If you have a relation you can try with this ON DELETE CASCADE option.
Another option is to create a stored procedure and do the delete in 2 steps but with only one server call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With