Hello again,
I'm almost embarrassed asking for help as what I'm trying to do (a
backgammon service) is all joy and no work... (Well, the joy takes
precedence😊)
Nonetheless, I'm stuck for the moment on the query below and could use
some help.
A match can have several games and in turn a game can have several
moves...
My query returns one row for each match and the highest (latest)
game_id for each match but it doesn't give me the player_id or
latest_move from the latest game in the match😟
How can I do that?
infogettable=# select distinct on (ma.match_id)
ma.match_id,
max(ga.game_id) as game_id,
mo.player_id,
mo.move_annotation as latest_move
from bg_matches ma, bg_games ga, bg_moves mo
where ga.match_id = ma.match_id
and mo.game_id = ga.game_id
group by ma.match_id, mo.player_id, mo.move_annotation
order by ma.match_id;
match_id | game_id | player_id | latest_move
----------+---------+-----------+--------------
1 | 1 | 4 | 10/6 9/1 9/5
2 | 2 | 6 | 24/21 13/11*
3 | 10 | 4 | 11/5 8/5
4 | 4 | 7 | 13/3(2)
5 | 5 | 7 | 13/10* 13/7
6 | 6 | 7 | 13/10 13/9
7 | 7 | 4 | 10/2
8 | 11 | 4 | 13/10 11/10
9 | 9 | 4 | 13/6
10 | 12 | 9 | 13/7
11 | 13 | 9 | 13/6
(11 rows)
Thanks,