Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete statement for unmatched records in 2 tables. 1

Status
Not open for further replies.

kavya

Programmer
Feb 21, 2001
83
US
Hi,

I have two tables tblsub and tblun they have a common field name 'filename'. I am trying to delte records in tblsub, if a record with filename is not found in tblun.
Tried different ways but still getting error.

Thanks in advance
 
DELETE FROM tblSub WHERE fileName NOT IN (SELECT fileName FROM tblUn) -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Be careful when using &quot;Not In (Select col from table)&quot;. This can create erroneous results if null values exist in the table of the subquery. See the article at


It is safer to use Not Exists.

DELETE FROM tblSub
WHERE Not Exists
(SELECT * FROM tblUn Where fileName=tblSub.fileName) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top