I have a table like this:
id c1 c2
1 5 abc
2 5 abc
3 2 xyz
4 2 xyz
5 68 sdf
I want to remove rows where c1 & c2 are same (that is row with id 2 and 4)
Edit: I tried
ALTER IGNORE TABLE jobs
ADD UNIQUE INDEX idx_name (c1, c2);
but got this
1834 – Cannot delete rows from table which is parent in a foreign key constraint ‘xyz’ of table ‘abc’
2
Answers
i suppose the table name is foobar , and c1 and c2 is not nullable .
this query will select the duplicate
You must create a temporary table with the list of all id you want to delete .
this query will delete the duplicate
This can be achieved in three steps.
This how I do a task like this. There may be a better way to do the same… Cheers!