About MySql delete using keys

Viewed 56

How to remove all the reminders belonging to the news created by Jack?

These are tables created by me with same data and now I want to fire SQL query for above requirement.

enter image description here

This is what I tried

DELETE FROM reminders
USING news
INNER JOIN reminders
WHERE CreatedBy = 'Jack'
      AND reminders.ReminderId = news.NewsId;
1 Answers

I find the USING syntax in MySQL deletes to be a bit confusing -- because USING is already used syntactically as a replacement for ON.

Something like this should work:

DELETE r
    FROM reminders r JOIN
         news n
         USING (NewsId)
    WHERE n.CreatedBy = 'Jack';

Note that the join condition is on NewsId in both tables.

Related