获得所有相等的字段

时间:2012-01-27 23:23:55

标签: mysql database

是否可以让mysql为我提供在一列中具有相同条目的所有行,无论它们看起来如何?

现在我使用了一些代码行,但我想让mysql完成这项工作!

2 个答案:

答案 0 :(得分:2)

Select field1, field2, field3
from Table
Where field3 = "Value"

那样的?还有更多问题吗?

答案 1 :(得分:1)

我认为这应该能够回报你需要的东西。问题很模糊。

-- Depending on your SQL syntax, this might work:

SELECT COUNT(*), colname FROM TABLE 
GROUP BY colname HAVING COUNT(*) > 1

-- or similarly,

SELECT FIELD, COUNT(FIELD) AS NumOccurrences 
FROM TABLE GROUP BY FIELD HAVING ( COUNT(FIELD) > 1 )

-- or if trying to find a duplicate combination 
-- of multiple columns,

SELECT column1, column2, column3, COUNT(column3) 
FROM TABLE GROUP BY column1, column2, column3 
HAVING COUNT(column3) > 1

'找到http://psoug.org/snippet/mySQL-Find-all-duplicates-in-a-column_353.htm'