How to delete duplicate rows in SQL table? Can I delete duplicate rows without a primary key? How to Select only unique rows using CTE?
For the demonstration purpose, I have created a dummy database with employee table. The table only has 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.
To select the unique rows, you can change the delete statement instead of deleting the rows. You can use delete statement with select * statement. And then, change the where condition to less than 2 instead of greater than 1.
Do you think that the article was helpful in solving your problem on how to delete duplicate rows in sql? Feel free to provide your comments and concerns in the below comment section.