Find duplicate column value in sqlite

自闭症网瘾萝莉.ら 提交于 2020-07-16 15:55:32

问题


I have inserted some values in the table DataTab.

SomeId: Integer     => Autogenerated primary key.
DataId: Guid
DataNumber: Integer
DataType: varchar

The above are the column's in my tables, I want to find, if the table contains Repeated DataId values. It has been long time I had worked with databases. Now I can figure out simple queries. But I found this some what difficult.

I tried the following query, is this correct?

SELECT * from (Select * from DataTab) AS X 
where DataId= X.DataId AND SomeId!=X.SomeId

回答1:


SELECT DataId, COUNT(*) c FROM DataTab GROUP BY DataId HAVING c > 1;



回答2:


I have used it in my application. It is working based on your query

SELECT a.* 
FROM CENTERDETAILS a 
JOIN 
(SELECT IPADDR, MACID, COUNT(*) 
    FROM CENTERDETAILS  
    GROUP BY IPADDR, MACID 
    HAVING count(*) > 1
) b ON a.IPADDR = b.IPADDR OR a.MACID = b.mac 
ORDER BY a.MACID


来源:https://stackoverflow.com/questions/21980064/find-duplicate-column-value-in-sqlite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!