Friday, May 30, 2008

[sql] Delete rows with join to another table in SQL Server

The non-obvious part is that you have to put the table name twice -- after the "delete" AND after the "from".



delete [TargetTable]
from [TargetTable]
join [JoinTable] on [TargetTable].[Column] = [JoinTable].[Column]

7 comments:

  1. Thanks, that's what I was looking for. Did you know that you're the 5th find on Google for the words "delete join"?

    ReplyDelete
  2. Over a year later and still helpful. Thank you for the information.

    ReplyDelete
  3. Thank you very much!!!!!! helped me alot

    ReplyDelete
  4. Thanks, this was really helpful!

    ReplyDelete