Current Data:
Expected Output: (After deleting the duplicates)
with cte AS ( select * from ( select *,row_number() over(partition by name order by id asc)as rowno from table )c where c.rowno>1 )delete from cte
WITH Data AS (SELECTColumnsname,ROW_NUMBER() OVER (PARTITION BY ColumnDuplicated ORDER BY ColumnDate DESC) AS AFROMTableName ) DELETE FROM Data WHERE A > 1;
You may use the below sample query to remove duplicate records.DELETE FROM your_table WHERE (unique_column1, unique_column2, created_at) IN (SELECT unique_column1, unique_column2, MAX(created_at)FROM your_tableGROUP BY unique_column1, unique_column2HAVING COUNT(*) > 1 );This SQL statement deletes duplicates by grouping the records based on unique_column1, unique_column2 and keeps only the latest record within each group. It uses MAX(created_at) to identify the latest record and removes duplicates where there are multiple records for the same unique columns.