deleting orphans

  • Hi I am trying to delete orphans from a table and I was wondering on the best way for this to be done.  At present I can only find the orphans, but I cannot find a way to delete them...I am using:

    delete

    from t1 where id =

    (select t1.id from t1

    left outer join t2

    on t1.id = t2.id

    where t2.id is null)

    But I cannot delete multiple rows this way.  Does anyone have any ideas?

  • DELETE FROM T1

    WHERE NOT EXISTS

    (SELECT *

     FROM T2

     WHERE Id = T1.Id)



    --Jonathan

  • That works great, thanks. 

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply