How do I delete multiple?

Discussion in 'MySQL' started by SametAras, Apr 25, 2011.

  1. #1
    Hello,

    I have got 3 tables as posts, posts_tags and tags. I want delete according to post ID. How do I manage it?

    My beginner query:

    DELETE tags,post_tags,posts FROM tags,post_tags,posts WHERE posts.id=133 AND tags.id = post_tags.tagid AND posts.id = post_tags.postid
    Code (markup):

     
    SametAras, Apr 25, 2011 IP
  2. jkl6

    jkl6 Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do it in 3 delete statements, in the following order.

    DELETE FROM tags WHERE tags.id in (SELECT post_tags.tagid FROM post_tags WHERE post_tags.postid=133;
    DELETE FROM post_tags WHERE post_tags.postid=133;
    DELETE FROM posts WHERE posts.id=133;
     
    jkl6, Apr 28, 2011 IP