Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
Duplication at what level? I mean based on how many fields do you identify a unique record?
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?
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:
Result:
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!