Skip to content
Advertisement

SQL : Finding duplicates and flag in separate column with Case

I am trying to find duplicates in the table and wanted to add a new flag column. Sample data below :

Desired output :

case 1: When Column A has the same values with different values in Column B (e.g. value 1 in Column A) – should be marked as DUPLICATE

case 2: When Column A has the same values with the same values in Column B in multiple rows(e.g. value 2 in column A) – should be marked as NULL

case 3: When Column A and Column B has unique values (e.g. value 3 and 4 in Column A) – Also should be marked as NULL

Any help would be appreciated.

Advertisement

Answer

You can use window functions:

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