If you would like to list duplicate rows with the count for a table, the following query would be helpful.
Query: Duplicate Rows
SELECT Column1,Column2,Column3,Count(*)
FROM dbo.TableName
GROUP BY Column1,Column2,Column3
HAVING ( COUNT(*) > 1 )
And there are scenarios where we need to find the combination of Columns in a table occurred only once. In such case the following query could be used.
Query: Unique combination of columns
SELECT Column1,Column2,Column3,Count(*)
FROM dbo.TableName
GROUP BY Column1,Column2,Column3
HAVING ( COUNT(*) = 1 )
Hope it helps.
Source : http://sapost.blogspot.in/
Query: Duplicate Rows
SELECT Column1,Column2,Column3,Count(*)
FROM dbo.TableName
GROUP BY Column1,Column2,Column3
HAVING ( COUNT(*) > 1 )
And there are scenarios where we need to find the combination of Columns in a table occurred only once. In such case the following query could be used.
Query: Unique combination of columns
SELECT Column1,Column2,Column3,Count(*)
FROM dbo.TableName
GROUP BY Column1,Column2,Column3
HAVING ( COUNT(*) = 1 )
Hope it helps.
Source : http://sapost.blogspot.in/
No comments:
Post a Comment
Hmmmmm... what are you thinking? Do not forget to comment,It helps us to improve this blog and help us to make better. on