SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete queries??

    How do you delete from multiple tables with 1 SQL statement?

    I tried something like:
    Delete from table1, table2 where key="$variable". Key would be a field in both tables. this didn't work.

    Help would be appreciated!!
    Becky

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you don't. at least not before MySQL 4.0. www.mysql.com/doc/D/E/DELETE.html
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've read the MySQL documentation and still don't see how to handle deleting from multiple tables. I want to ensure that all data pertaining to the selection is deleted from both tables - what would be the best way of getting this done????

    the variable I'm using would be primary key in one table and foreign key in the other table.

  4. #4
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like Dr_larry_pepper had mentioned, multiple table deletion isn't supported by mysql until version 4.0. If you aren't running this version of mysql, you're going to have to run the queries sequentially.

    The syntax to do multiple deletes is on the link that he had pasted.

    DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id


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
  •