samedi 5 septembre 2015

Removing duplicate row from SQLite3

I have a SQLite3 DB with ~10,000 rows of data.

The schema is like this:

id, stock_id, body, stock_created_at, symbol, updated_at, created_at

The PK is id with no FK

You can tell there is a duplicate if the stock_id is duplicated.

I have a MySQL query like this that I used to use, but it's for MySQL and not SQLite:

DELETE FROM stocks WHERE id NOT IN
    (SELECT MAX(id) FROM table GROUP BY stock_id);

Aucun commentaire:

Enregistrer un commentaire