Find duplicate column value in sqlite
DatabaseSqliteDatabase Problem Overview
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
Database Solutions
Solution 1 - Database
SELECT DataId, COUNT(*) c FROM DataTab GROUP BY DataId HAVING c > 1;
Solution 2 - Database
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