How to delete duplicate record in SQL ?

Forums SQLHow to delete duplicate record in SQL ?
Staff asked 3 weeks ago

Answers (1)

Add Answer
Umang Ramani Marked As Accepted
Staff answered 3 weeks ago

Try with this :

WITH cte AS (
    SELECT 
        contact_id, 
        first_name, 
        last_name, 
        email, 
        ROW_NUMBER() OVER (
            PARTITION BY 
                first_name, 
                last_name, 
                email
            ORDER BY 
                first_name, 
                last_name, 
                email
        ) row_num
     FROM 
        sales.contacts
)
DELETE FROM cte
WHERE row_num > 1;

 

 

Subscribe

Select Categories