how can i get rows with similar column value
我怎样才能获得具有相似列值的行
1 个解决方案
#1
So you want to find rows that have the same value in a column as another row in the same table?
那么您希望在列中找到与同一个表中的另一行具有相同值的行?
SELECT columName FROM tablename GROUP BY columnName HAVING COUNT(columnName) > 1
Edit:
If you want to get all the rows with a non-unique value in the column, you can use the above query in an IN clause:
如果要在列中获取具有非唯一值的所有行,可以在IN子句中使用上述查询:
SELECT * FROM tablename
WHERE columnName IN (
SELECT columName FROM tablename
GROUP BY columnName
HAVING COUNT(columnName) > 1
)
The inner query will find all the column values that are duplicated, and the outer query will return all the rows that have matching column values.
内部查询将查找所有重复的列值,外部查询将返回具有匹配列值的所有行。
#1
So you want to find rows that have the same value in a column as another row in the same table?
那么您希望在列中找到与同一个表中的另一行具有相同值的行?
SELECT columName FROM tablename GROUP BY columnName HAVING COUNT(columnName) > 1
Edit:
If you want to get all the rows with a non-unique value in the column, you can use the above query in an IN clause:
如果要在列中获取具有非唯一值的所有行,可以在IN子句中使用上述查询:
SELECT * FROM tablename
WHERE columnName IN (
SELECT columName FROM tablename
GROUP BY columnName
HAVING COUNT(columnName) > 1
)
The inner query will find all the column values that are duplicated, and the outer query will return all the rows that have matching column values.
内部查询将查找所有重复的列值,外部查询将返回具有匹配列值的所有行。