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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete from table based on no match to another table 1

Status
Not open for further replies.

trenttc

Technical User
Feb 25, 2002
68
US
The following was posted in another forum. It's to delete all Table1 records not found in Table2. How can this be done in ASA since it complains about the asterisk?

DELETE Table1.*
FROM Table1 LEFT JOIN Table2
ON Table1.YourField1 = Table2.YourField2
WHERE Table2.YourField2 Is Null;
 
hello,

try this...

assuming of course that there is FK constraint between tableName1 and tableName2...

use databaseName
go

begin tran
go

delete tableName1
where columnName1 not in
(select columnName2
from tableName2)
go

commit tran/rollback tran
go

hth,
q.
 
Can you not just say ...

DELETE Table1
FROM Table1, Table2
WHERE Table1.YourField1 = Table2.YourField2
AND Table2.YourField2 Is Null

Greg.
 
qyllr's solution works. I was not aware you could code statements in this manner.
 
...or

Delete TargetTable
From TargetTable target
Where Not Exists
( Select 1 From RafTable ref
Where ref.SomeKey = target.SomeKey
)

...just a quick thought.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top