how can i get rows with similar column value
Asked
Active
Viewed 1,283 times
0
-
1Can you add some more information? Is your column a number or string, etc.? – Andy White May 28 '09 at 06:07
-
my column is a number..i just want to get the rows which hava the duplcacy for this column.. – saurabh May 28 '09 at 06:11
1 Answers
4
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:
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.

Rytmis
- 31,467
- 8
- 60
- 69