Delete duplicate rows with different statuses

libpekin 166 Reputation points
2023-08-10T18:12:24.62+00:00

help with deleting duplicate order rows for orders processed multiple times, but only if the duplicate is caused by submit_status 0 or 1. Basically, orders that failed on first attempt but got processed manually. Also, if a duplicate order has the same submit_status, then keep it.

sample data attached. Thank you!

User's image

SQL Server | Other
{count} votes

Answer accepted by question author
  1. Viorel 125.8K Reputation points
    2023-08-10T18:48:11.42+00:00

    Check this statement:

    delete t1
    from MyTable t1
    inner join MyTable t2 on t1.orderId = t2.orderId and t1.submit_Status <> t2.submit_Status
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.