SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple tables records deletion. How?

    Hi,

    I've 4 tables from which i need to delete rows. Below are the tables:

    Table s
    Table a
    Table v
    Table p

    1. Column a_sid of table "a" references column s_id of table "s" where s_id is primary key so as a_sid.
    2. Column v_sid of table "v" references column s_id of table "s"
    3. Column p_sid of table "p" references column s_id of table "s"

    I need to delete all rows of 4 tables where a_type of "a" table = "AC"

    Please help.
    Thanks,
    Ramki

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    From the manual:
    Code:
    DELETE t1, t2, t3 FROM t1 INNER JOIN t2 INNER JOIN t3
    WHERE t1.id=t2.id 
    AND   t1.id=t3.id
    You just need to change it a bit and adapt it to your situation

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guido. It worked

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by guido2004 View Post
    From the manual:
    Code:
    DELETE t1, t2, t3 FROM t1 INNER JOIN t2 INNER JOIN t3
    WHERE t1.id=t2.id 
    AND   t1.id=t3.id
    eeeeeeeeewwwwwwwwwwwwww!!!!!!

    i didn't believe it until looked it up, and that is indeed what it says

    please, let's not ever show anyone that particular example again

    instead, let's show them this --
    Code:
    DELETE t1, t2, t3 
      FROM t1 
    INNER 
      JOIN t2 
        ON t2.id = t1.id
    INNER 
      JOIN t3
        ON t3.id = t1.id
    thank you
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by r937 View Post
    eeeeeeeeewwwwwwwwwwwwww!!!!!!

    i didn't believe it until looked it up, and that is indeed what it says

    please, let's not ever show anyone that particular example again
    You know, I had some doubts, so I read it twice and looked at the whole page in search of some 'ON' clause, but there wasn't, so I assumed in the case of multiple table deletes the MySQL syntax was different...
    I'm glad you confirm my doubts


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •