Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

count for columns which contain duplicate values

I need count for some columns in which multiple columns contain duplicate values.

I have one view which is created from many tables by sql server 2014 and i am creating report and i need count from that view but it contains duplicate values for different columns along with different values for same row. so can i apply filters to get this?

3 Replies
suryaa30
Creator II
Creator II

Duplication at what level? I mean based on how many fields do you identify a unique record?

Anonymous
Not applicable
Author

i have to remove the duplication on the basis of 5 primary keys ( columns ) in a table.... so please tell me how may i do that?

Anonymous
Not applicable
Author

I am taking a dummy dataset where I need to find duplicates for fields A and B. Introduce a column [count] =1.

Do a left join to a second table which only has the DISTINCT key fields. I have taken A and B here. sum(count) will tell you how many times the combination for A and B occurs.

Code:

duplicate_1.JPG

Result:

duplicate_2.JPG

We can see that even though column C is different in the first two rows, it is considering only columns A and B, which you can change to your 5 key fields.

Let me know if this helps!