Skip to content
Advertisement

Avoid duplicates rows which have one different column value in SQL Server

I have a view like this . I’m using SQL Server.

view name: view_example

There, some formId’s have two kinds of mark values as N and C. and some have single values as N. I want to print this to a report if formid is duplicating with different mark values, print the raw with mark value C . If form id is not duplicating print the value as it is. out put should look like this

I want to write the SQL query for this.

Advertisement

Answer

You could GROUP BY all the columns where you want to preserve all the values, and apply an aggregate function (in this case – MIN, in order to give C precedence over N) on the mark column:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement