peps03
asked on
Delete double rows in mysql database
Hi,
I have a table (table1) with 3 columns, id, text, flag.
The table contains tens of thousands of rows with some text.
Some of these rows are doubles.
I tried this query below to delete these double entries, but it runs for hours and deletes nothing.
DELETE n1 FROM table1 n1, table1 n2 WHERE n1.id > n2.id AND n1.text = n2.text
Does anybody have a better (working) and faster query?
Thanks!
I have a table (table1) with 3 columns, id, text, flag.
The table contains tens of thousands of rows with some text.
Some of these rows are doubles.
I tried this query below to delete these double entries, but it runs for hours and deletes nothing.
DELETE n1 FROM table1 n1, table1 n2 WHERE n1.id > n2.id AND n1.text = n2.text
Does anybody have a better (working) and faster query?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You query looked more like what a programmer would try than what SQL would expect.
You were JOINining your table with itself on the text field, which I guess was not indexed.
It created a huge table and I don't really know what MySQL was trying to do with it.
You were JOINining your table with itself on the text field, which I guess was not indexed.
It created a huge table and I don't really know what MySQL was trying to do with it.
ASKER
Ok, thanks!
ASKER
That worked! Very quickly!!
What was wrong with my query? A lot?