Published on

Delete Rows with Duplicated Column Value in SQLite

Problem

idwordcreated_at
1hello2023-05-05 10:12:13
2hello2023-05-05 10:12:13
3hello2023-05-05 10:12:13
4dog2023-05-05 10:12:13
5dog2023-05-05 10:12:13
6cat2023-05-05 10:12:13

We want to have resulted data like

idwordcreated_at
1hello2023-05-05 10:12:13
4dog2023-05-05 10:12:13
6cat2023-05-05 10:12:13

Solution

DELETE FROM words WHERE id NOT in (
        SELECT MIN(id) FROM words GROUP BY word
    );

Reference