开发者

check duplicate mysql row

I have a mysql table that contains field_one, field_two, field_three

I want to check if field_one contains a duplicate value (like if it was unique).

How to do that in mysql?

Th开发者_JAVA技巧anks


This will show you values for field_one that occur more than once:

select field_one, count(*) as Count
from MyTable
group by field_one
having count(*) > 1


select field_one from tblName where field_one like %'@field_one'%

or

select field_one from tblName where field_one = @filed_one


If you just need to check if all values are unique in one column, you could use this to count all unique values:

select Count(Distinct column) from table

...and compare it to the the number of all values in the column:

select Count(column) from table

This might consume a lot of memory on large tables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜