Both the below queries work fine - thank you.
However my issue is now further complicated. For reasons relating to my
application I have to display the high score as a concatenated text
field. The actual score is part of that but there are some game specific
qualifiers.
In the table you refer to as [MyTable] I have two additional fields which
are used, one is 'Wkts' and the other is 'Dec' (which is true of false).
What I actually need to display can be created in MyTable using:
ScoreText: [MyTable]!Score &
IIf([MyTable]!Wkts>9,"",IIf([MyTable]!Dec=True,"-" & [MyTable]!Wkts & "
dec","-" & [MyTable]!Wkts))
e.g. Score = 270, wkts = 4, and Dec = True gives "270-4 dec"
or Score = 125, wkts = 9, and Dec = False gives "125-9"
I had hoped to just substitute ScoreText for Score in your query, but
obviously this does not work, although I am not sure why.
SELECT ClubName, ScoreText, First(Opponents) As OppoName
FROM [MyTable] AS T
WHERE T.ScoreText = SELECT Max(T1.ScoreText) FROM [MyTable] as T1 WHERE
T1.ClubName = T.ClubName
GROUP BY ClubName, ScoreText
I have made sure that the order is correct in [MyTable] by doing the
appropriate sorting on Score and Wkts Columns. The highest score is the
first record for each team as it is encountered.
This works for eight of the ten teams in my test data, but not two.
John Spencer said:
SELECT Score, Team, Opponents
FROM [Your Table] as T
WHERE T.Score =
(SELECT Max(T1.Score)
FROM [Your Table] as T1
WHERE T1.Team= T.Team)
That will give you multiple records if the Max Score for any Team has
ties. If you don't want "ties", then you can try
SELECT Score, Team, First(Opponents) as TheOpponent
FROM [Your Table] as T
WHERE T.Score =
(SELECT Max(T1.Score)
FROM [Your Table] as T1
WHERE T1.Team= T.Team)
GROUP BY Score, Team
I have a table which contains the following fields (which represent
results):
Score, Team, Opponents
I needs a query that will return the highest score for each team AND
who the opponent was in that game.
It is a simple matter to Group by Team and then find the max of Score,
this returns the highest score for each team. However as soon as I add
the Opponent field the max clause no longer works and I just get every
result in the table.
How do I achieve what I need?