I would like to delete all the rows in a table where the names of a column are the same...
But I do not know the names of the values in column_1.
Always column_1 will be the one with repeats... column_2 will not. It's possible to do that? Thank you.
Example:
| column_1 | column_2 |
|---|---|
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
| 3 | 5 |
| 4 | 6 |
| 5 | 7 |
| 5 | 8 |
| 5 | 9 |
Expected:
| column_1 | column_2 |
|---|---|
| 1 | 2 |
| 2 | 3 |
| 4 | 6 |
CodePudding user response:
Use a subquery to help you with that:
DELETE FROM `TableName` where column_1 in
(select column_1 FROM
(select column_1 FROM `TableName` GROUP BY `column_1` HAVING count(column_1)>1) AS t1
)
