I have the following table:
Id CategoryId Code Status
=================================
1 A100 0012 NULL
2 A100 0012 NULL
3 A100 0055 NULL
4 A100 0012 NULL
5 B201 1116 NULL
6 B201 1116 NULL
7 B201 1121 NULL
8 B201 1024 NULL
Logic: 1. For same CategoryID, code should be the same.
2. If multiple code exists, consider the one with lowest value.
Desired result:
Id CategoryId Code Status
=================================
1 A100 0012 NULL
2 A100 0012 NULL
3 A100 0055 FAIL
4 A100 0012 NULL
5 B201 1116 FAIL
6 B201 1116 FAIL
7 B201 1121 FAIL
8 B201 1024 NULL
Thanks
Following your edit…
Returns