I'm working on a sports database, and I want to write a query that will return the name and the statistical value for certain categories. For example, goal leader, assist leader, points leader, +/- leader, penalty minutes leader, etc. I am using a table called NJDSkaters which contains player names and stats from a specific team. Here is the query code:
SELECT CONCAT(PlayerName,' - ',Goals) AS GoalLeader, CONCAT(PlayerName,' - ',Assists)
CONCAT(PlayerName,' - ',Points) AS PointsLeader
FROM NJDSkaters
WHERE Goals = (SELECT DISTINCT MAX(Goals) FROM NJDSkaters)
OR Assists = (SELECT DISTINCT MAX(Assists) FROM NJDSkaters)
OR Points = (SELECT DISTINCT MAX(Points) FROM NJDSkaters);
Here is a snippet from my skater register table which will show the players who should be returned by this query:
As you can see, my desired return query should have 'Ilya Kovalchuk - 37' returned as GoalLeader, 'Patrik Elias - 52' as AssistLeader, and 'Ilya Kovalchuk - 83' as PointsLeader. Running the query does provide these results, but there is extra information included that I do not want, as you can see here:
My question is, how do i get rid of the excess information? I only want the leaders in each category, and I don't want to see the #2 player listed, even if that player is #1 in some other category. Essentially, what I'm saying, is I want only 1 row in this table. Before, I had code that would return all players with the leaders at the top, so this code is a step closer to my desired result, but now I'm stuck. Searching for an answer to this problem has been challenging, as finding a way to ask it generally is difficult.