Registros repetidos

Algunos queries útiles para lidiar con con registros repetidos.

Encuentra lor registros repetidos junto con el número de veces que están repetidos.

SELECT DISTINCT(column_id), count(column_id)
    FROM table_name
    GROUP BY column_id
    HAVING (count(column_id)>1)

Para borrar los repetidos:

DELETE FROM table_name where rowid NOT IN
 (SELECT max(rowid) FROM table GROUP BY duplicate_values_field_name);

Una alternativa para borrar

DELETE  duplicate_values_field_name dv FROM table_name ta 
WHERE rowid <(SELECT min(rowid)  FROM table_name tb 
WHERE ta.dv=tb.dv);
Advertisements

One thought on “Registros repetidos

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s