Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-21-2007, 04:49 PM   PM User | #1
Afrow UK
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 177
Thanks: 0
Thanked 2 Times in 2 Posts
Afrow UK is an unknown quantity at this point
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 :)~;
}
Afrow UK is offline   Reply With Quote
Old 03-21-2007, 05:22 PM   PM User | #2
chris.hurd
New to the CF scene

 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
chris.hurd is an unknown quantity at this point
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...
chris.hurd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:25 AM.


Advertisement
Log in to turn off these ads.