Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 check 2 tables a delete records based on common fi

Author  Topic 

kswebwerx
Starting Member

1 Post

Posted - 2007-08-08 : 11:10:12
I'm kinda embarrased, it's been quite awhile since I've played with SQL or Access but here's my brain fart. I need to open an access DB by the name of eHomes. Inside there are two tables AD_IMAGE & PROPERTY. Property is the main table and stores most of the info. It has a field in it called AD_ID and others except for the image file name. The AD_IMAGE table just keeps the image file name and has 3 fields: ID - AD_ID - & Image1. The problem is when the ad is deleted from the property table the AD_IMAGE table record referring to the PROPERTY.AD_ID doen't get deleted. So, I just want the AD_IMAGE table cleaned up to match what's active in the PROPERTY table using the common AD_ID fields in both tables.

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-08-08 : 11:41:45
delete AD_IMAGE
where AD_ID not in (select AD_ID from PROPERTY)

delete AD_IMAGE
from AD_IMAGE
left join PROPERTY
on PROPERTY.AD_ID = AD_IMAGE.AD_ID
where PROPERTY.AD_ID is null

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -