patternsqlMinor
SQLite3 - remove duplicates by multiple columns
Viewed 0 times
columnssqlite3removemultipleduplicates
Problem
I'm looking for the most efficient way to remove duplicates from a table where id's are unique but there are equal rows when you check other columns.
Example:
The table has tens of thousands of rows.
Example:
id name age x
1 peter 25 II
2 peter 25 IIThe table has tens of thousands of rows.
Solution
Supposing you have no foreign keys referencing that table, you could do something like
then you can drop the old table, rename the new table so that it has the same name as the old one before, and create indexes and other things you need on that table.
create table some_table as
select min(id), name, age, x
from t
group by name, age, xthen you can drop the old table, rename the new table so that it has the same name as the old one before, and create indexes and other things you need on that table.
Code Snippets
create table some_table as
select min(id), name, age, x
from t
group by name, age, xContext
StackExchange Database Administrators Q#101697, answer score: 5
Revisions (0)
No revisions yet.