Find duplicate column value in sqlite

DatabaseSqlite

Database 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question51kView Question on Stackoverflow
Solution 1 - DatabaseJwalin ShahView Answer on Stackoverflow
Solution 2 - DatabaseAshok Kumar JView Answer on Stackoverflow