Link to home
Start Free TrialLog in
Avatar of peps03
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!
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03
peps03

ASKER

Thanks Dan!
That worked! Very quickly!!

What was wrong with my query? A lot?
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.
Avatar of peps03

ASKER

Ok, thanks!