Deleting based on date NOT in another table

Deleting based on date NOT in another table

Post by Scott Cilibert » Sat, 08 Mar 2003 09:51:36



I'm trying to do some data cleanup, and I need to delete
rows in a table based on the primary key not existing in
another table.  Here's the pseudocode:

Delete from table 1
where table 1.primary key isn't in table 2.primary key

Any ideas how to create the join?

 
 
 

Deleting based on date NOT in another table

Post by Vishal Parka » Sat, 08 Mar 2003 22:12:05


Delete from table1
where id not in(select id from table2)

above query will delete rows from table1 for the id that
does not exists in table2

following query would do the same

Delete from table1
where not exists(select 1 from table2
where table2.id = table1.id)

--Vishal

Quote:>-----Original Message-----
>I'm trying to do some data cleanup, and I need to delete
>rows in a table based on the primary key not existing in
>another table.  Here's the pseudocode:

>Delete from table 1
>where table 1.primary key isn't in table 2.primary key

>Any ideas how to create the join?
>.