database 在sqlite中查找重复的列值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21980064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find duplicate column value in sqlite
提问by 51k
I have inserted some values in the table DataTab.
我在表中插入了一些值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 DataIdvalues.
It has been long time I had worked with databases. Now I can figure out simple queries. But I found this some what difficult.
以上是我表中的列,我想查找表中是否包含重复DataId值。我使用数据库已经很长时间了。现在我可以弄清楚简单的查询。但我发现这有些困难。
I tried the following query, is this correct?
我尝试了以下查询,这是正确的吗?
SELECT * from (Select * from DataTab) AS X
where DataId= X.DataId AND SomeId!=X.SomeId
回答by Jwalin Shah
SELECT DataId, COUNT(*) c FROM DataTab GROUP BY DataId HAVING c > 1;
回答by Ashok Kumar J
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

