检查重复的 mysql 行

发布于 2024-11-13 00:36:31 字数 174 浏览 2 评论 0原文

我有一个 mysql 表,其中包含 field_onefield_twofield_third

我想检查 field_one 是否包含重复值(例如它是否是唯一的) 。

在mysql中如何做到这一点?

谢谢

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?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光倒影 2024-11-20 00:36:31

这将显示多次出现的 field_one 值:

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

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
溇涏 2024-11-20 00:36:31
select field_one from tblName where field_one like %'@field_one'%

或者

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

or

select field_one from tblName where field_one = @filed_one
寒江雪… 2024-11-20 00:36:31

如果您只需要检查一列中的所有值是否唯一,您可以使用它来计算所有唯一值:

select Count(Distinct column) from table

...并将其与该列中所有值的数量进行比较:

select Count(column) from table

这可能会消耗大量内存大桌子。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文