SQLite Forum

Delete duplicate rows with an extra character
Login
One presumes you mean something like this:

```
DELETE FROM players o
      WHERE player_tag like '#%'
        AND EXISTS (
                    SELECT 1
                      FROM players
                     WHERE player_tag == substr(o.player_tag, 2)
                    )
;
```

The original, although it can be made to work, is flawed in that it processes all rows in the table, rather than just the rows that might need to be deleted.  If you limit the examiation to only those rows implies that there is always a '#' as the first character so there is no need to search for it.

However, the following statements might be faster:

```
UPDATE OR IGNORE players
             SET player_tag = substr(player_tag, 2)
           WHERE player_tag like '#%'
;
DELETE FROM players
      WHERE player_tag like '#%'
;
```