• This is a pretty good technique, but there are problems with it.  Using derived tables in a query can be very powerful, but they can also cause excessive use of tempdb (similar to using # tables).  Often, there are other ways of doing the same thing for cheaper.

    So, if you don't have to use them, don't.  The query below is functionally equivalent to the delete statement in the article, but it costs almost half.

    delete p1

    From Payment p1

    JOIN Payment p2

       on  p1.CustomerNumber = p2.CustomerNumber and

        p1.PostedDateTime = p2.PostedDateTime and

        p1.PaymentAmt   = p2.PaymentAmt

    where p1.PaymentID < p2.PaymentID

     

    Signature is NULL