问题
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