0

I have a python script that inserts rows into a table. I want it to either delete duplicate rows or ignore the INSERT if the row exists. What I have tried so far:

#delete duplicate entries
c.execute('''DELETE FROM server WHERE sites NOT IN
            (SELECT MIN(sites) sites FROM server GROUP BY sites)''')

The table "server" is a single column "sites". This is a table of web sites. It's not throwing any errors. It's just doesn't not deleting the duplicates.

1 Answer 1

1

Comparing against the sites itself does not help, because the duplicates have the same value in this column.

You have to use some other column that is unique. In this case, you could use the rowid:

DELETE FROM server
WHERE rowid NOT IN (SELECT min(rowid)
                    FROM server
                    GROUP BY sites);
Sign up to request clarification or add additional context in comments.

1 Comment

That was it. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.