0

I try to delete duplicate (service column) but not working

DELETE FROM contactactionnodup
WHERE service IN (SELECT service, COUNT(*), contactid
                  FROM ContactActionNoDup 
                  GROUP BY service, contactid
                  HAVING COUNT(*) > 1)

Need to correct this query. Thank you

1 Answer 1

2

If you want to keep one of the rows for each service/contactid pair, then use an updatable CTE:

with todelete as (
      select ca.*, row_number() over (partition by service, contactid order by service) as seqnum
      from ContactActionNoDup as ca
     )
delete from todelete
    where seqnum > 1;
Sign up to request clarification or add additional context in comments.

1 Comment

what is ca.* and I don't understand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.