Skip to content
Advertisement

How to handle duplicates created by LEFT JOIN

LEFT TABLE:

RIGHT TABLE:

DESIRED OUTPUT:

The closest I get is this:

Which gives:

I can’t figure out how to get rid of Bonus duplication. Ideal solution for me would be as specified in the ‘DESIRED OUTPUT’, which is adding Bonus to only one Name and for other records with the same Name adding 0.

Advertisement

Answer

Try a Row_number over the Name category partioned by Name. This will give you different numbers for your duplicates. You can then search for the case when this number is 1 and return the result you want. Else return 0. The code can look something like this.

Hope that helps!

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