views:

137

answers:

1

how can i get rows with similar column value

+2  A: 

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

related questions