I need to return all data for rows where one particular field in the row is the same for each record, but I can't use group by
because I need to see all the duplicated records; I don't just want a count of them.
I've tried using group by
and having count(field) > 1
and various forms of simple select
and other ways of trying to use count()
with no luck.
There are additional where
requirements, but for simplicity I'm not including them here. I'm using SSMS 2008 R2.
Example:
Data:
Col1 | Col2 | Col3
----------------------
abc wow 13/05/2016
abc wow 10/05/2016
def wow 13/05/2016
ghi wow 13/05/2016
ghi wow 10/05/2016
jkl wow 01/01/2016
Expected result:
Col1 | Col2 | Col3
----------------------
abc wow 13/05/2016
abc wow 10/05/2016
ghi wow 13/05/2016
ghi wow 10/05/2016
I am looking to show anything that does not have a unique value in Col1
2条答案
按热度按时间b1zrtrql1#
You can use the following query:
The query uses window version of
COUNT
aggregate function: the function is applied overCol1
partitions. The outer query filters out records which have aCol1
value that appears only once.hwazgwia2#
It isn't very clear what you are trying to do but maybe something like this is what you are looking for?