- Delete duplicate rows from SQL table.
- How to delete duplicate rows without a primary key?
- Select only unique rows using CTE.
For the demonstration purpose, I have created a dummy database with employee table. which has only name column with multiple duplicate values.
Scripts for dummy data
As you can see in the above Emp table only one column is available, with multiple duplicate values. our task is to remove the duplicate values and keep only unique values in the table.
Not to worry, with the help of CTE or common table expression, we can easily achieve this.
In case you want to select the unique rows instead of deleting the rows. you need to change the delete statement with the select * statement and change the where condition from greater then 1 to less then 2.