sql - FInding Duplicate records in a table and deleting those records using postgreSQL -


i have table named "cities" has columns "id", "state" , "cities". there duplicate records found in table. want records found , deleted table. note query should found , delete record if both state , city names same.how can done using postgresql.

assuming id unique (as implied question), can use delete id:

delete cities c     c.id > (select min(c2.id)                   cities c2                   c2.state = c.state , c2.cities = c.cities                  ); 

if id can same, can use ctid:

delete cities c     c.ctid > (select min(c2.ctid)                     cities c2                     c2.state = c.state , c2.cities = c.cities ,                           c2.id = c.id                    ); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -