Delete rows in one table based on another table

  • I need a SQL statement that will delete the rows in one table if that value exists in another table.

    The first table has a list of file paths that I want to delete if those file paths exist in table 2.

    Help is much appreciated.

  • You can do that a couple of ways.

    delete from dbo.Table1

    where Path in

    (select Path

    from dbo.Table2)

    delete from dbo.Table1

    from dbo.Table1

    inner join dbo.Table2

    on Table1.Path = Table2.Path

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks a bunch.

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

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