Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete one of two perfectly identical rows?

I am cleaning out a database table without a primary key (I know, I know, what were they thinking?). I cannot add a primary key, because there is a duplicate in the column that would become the key. The duplicate value comes from one of two rows that are in all respects identical. I can't delete the row via a GUI (in this case MySQL Workbench, but I'm looking for a database agnostic approach) because it refuses to perform tasks on tables without primary keys (or at least a UQ NN column), and I cannot add a primary key, because there is a duplicate in the column that would become the key. The duplicate value comes from one...

How can I delete one of the twins?

like image 745
lofidevops Avatar asked May 08 '13 10:05

lofidevops


People also ask

How can I delete duplicate rows in a table?

To delete the duplicate rows from the table in SQL Server, you follow these steps: Find duplicate rows using GROUP BY clause or ROW_NUMBER() function. Use DELETE statement to remove the duplicate rows.


1 Answers

SET ROWCOUNT 1 DELETE FROM [table] WHERE .... SET ROWCOUNT 0 

This will only delete one of the two identical rows

like image 113
Rinaldo Avatar answered Oct 08 '22 20:10

Rinaldo