Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    177
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Delete records without matching records

    I have a one to many relationship in my database.
    I would like to delete records in one table if there are no matching records in another table.

    Cheers

    Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

  • #2
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are using a version earlier then 4.0 you are out of luck..you will need to do it in a script.

    If after 4.0 you could do something like

    DELETE FROM table1 WHERE table1_id NOT IN (SELECT distinct table1_id FROM table2)

    remember to do a dump before doing any mass deletes though...


  •  

    Posting Permissions

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