SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Delete by join

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete by join

    How can i delete the records from another table on the behalf of the records from from first table

    Delete from second_table where ref_no=(SELECT ref_number FROM `first_table` WHERE category =7 AND subcat1 =85)

  2. #2
    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)
    Code:
    DELETE second_table
      FROM first_table
    INNER
      JOIN second_table 
        ON second_table.ref_no = first_table.ref_number 
     WHERE first_table.category = 7 
       AND first_table.subcat1 = 85
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much :-)


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
  •