showing the last 20 results from a union query

P

pat67

I have a union query showing the results from pool matches

GameID Player Opponent Result
1 Joe Bob Won
2 Jim Bill Won
1 Bob Joe Lost
2 Bill Jim Lost

Obviousy a lot more games but that is the premise. What i am looking
for is to show the last 10,20 whatever results for each player. Total
record is easy, just count won and lost. But I am not sure how do get
the last 20 games for each player. Can someone help?

Thanks
 
G

ghetto_banjo

Do you store the date/time of these matches? If not, it looks like
the only way to grab the "last" 20 matches would be via the GameID.

I am not sure how your table is setup exactly, but this should point
you in the right direction.

SELECT TOP 20 GameID, Player, Opponent, Result
FROM tblMatches
WHERE Player = 'Joe'
ORDER BY GameID DESC;
 
P

pat67

Do you store the date/time of these matches?  If not, it looks like
the only way to grab the "last" 20 matches would be via the GameID.

I am not sure how your table is setup exactly, but this should point
you in the right direction.

SELECT TOP 20 GameID, Player, Opponent, Result
FROM tblMatches
WHERE Player = 'Joe'
ORDER BY GameID DESC;

I want to do it for every player. i do have a date, but need to use
the ID since a player normally plays 3 or 4 games a night.
 
P

pat67

I want to do it for every player. i do have a date, but need to use
the ID since a player normally plays 3 or 4 games a night.

To be more specific, i need to show the GameID for each player in
descending order.
 
G

ghetto_banjo

Try this out. You need to use a subquery to get Top results per
Player.

SELECT tblMatches.Player, tblMatches.Opponent, tblMatches.Result,
tblMatches.GameID
FROM tblMatches
WHERE tblMatches.GameID IN (SELECT TOP 2 GameID From tblMatches AS
Dupe WHERE Dupe.Player = tblMatches.Player ORDER BY Dupe.GameID DESC)
ORDER By tblMatches.Player, tblMatches.GameID DESC;
 
G

ghetto_banjo

No problem, glad it worked. those subqueries get confusing,
especially when referencing the same table as main query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

help with ranking in a query 2
getting players records vs. other players 7
query grouping issue 4
query to get top player 8
crosstab query question. 3
crosstab query? 3
SUM in a UNION query 2
Tennis Scorecard Help 1

Top