I'm trying to write a query that will display the minimum value (lowest score) for each hole eliminating any duplicates. In other words, if the minimum score is 3 on hole_num 1 and there are two or more scores with 3, none of the rows corresponding to hole_num 1 should be returned. However, if there is only one value of 3 on hole_num 1 and it is the minimum value, the row should be returned. Here is what I was able to come up with... unfortunately I can't figure out how to remove the duplicates.
sample table:
player_id hole_num score
------------- ------------ -----
1 1 4
1 2 5
2 1 3
2 2 5
my query that gets the minimum score for each hole_num (but does not eliminate the row if it occurs more than once):
select. r.player_id, r.hole_num, r.score
from scorecard_test r
join (select hole_num,
min(score) best
from scorecard_test
group by hole_num) v on r.hole_num = v.hole_num
and r.score = v.best
produces the following output:
player_id hole_num score
---------- --------- -----
1 2 5
2 1 3
2 2 5
I'm trying to write a query that would only display the second row above (score=3) since 5 on hole_num 2 (although it is minimum) is a repeat. Any help would be greatly appreciated.