how can I delete duplicates in SQLite?

旧时模样 提交于 2019-11-28 11:04:37

SQLite has a special column, ROWID created on every table by default (you can switch it off using the WITHOUT ROWID modifier, but be very sure before doing so).

This means that we can identify specific rows within sets of duplicates, for example, finding the first entry for a value:

SELECT messdatum, MIN(ROWID) FROM lipo

So one way to remove duplicates might be this:

DELETE FROM lipo
WHERE rowid NOT IN (
  SELECT MIN(rowid) 
  FROM lipo 
  GROUP BY messdatum
)

I got the solution:

 INSERT into holdkey SELECT messdatum, count(*) as anzahl,NameISO from lipo group by messdatum having count(*) > 1;
 INSERT into holddups SELECT DISTINCT lipo.*,1 from lipo, holdkey where lipo.Messdatum = holdkey.messdatum group by messdatum;
 INSERT into lipo_mit_dz  SELECT *, count(*) as DublettenZahl from lipo group by messdatum ORDER BY Dublettenzahl desc ;
 DELETE from lipo_mit_dz where Dublettenzahl > 1;
 INSERT into lipo_mit_dz SELECT * from holddups ; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!