I have a small MS Access database containing four tables and are struggeling with a MAX(Date) query which involves all tables. Any help will be greatly appreciated.
Overview of the database:
TABLE COLUMNS
Person Person_ID |....
Games Game_ID | Name |....
Played_Games Played_Games_ID | Game_ID | Date |....
Participation Played_Games_ID | Person_ID |...
To list out all games and what date each of them were last played by any person I use:
SELECT DISTINCT Games.Name,
(SELECT MAX(Date) FROM Played_Games WHERE Played_Games.Game_ID = Games.Game_ID) AS Date_Last_Played
FROM Games
ORDER BY Games.Name
This works great, but I would also like to list what date each of them were last played by members of a certain group of persons. Any help with that will be greatly appreciated.
I asked a somewhat similar question some days ago, but then my goal was to list out all games, how many times each game is played in total and how many times each games is played by members of a certain group of persons (Persons 1 and 2 are just an example). GarethD helped me out with that one just perfect by the code below. I've tried to alter this code to solve my new task, cause I guess much of this logic/structure can be reused, but so far I've not been successful on my own :-(
SELECT Games.Name,
IIF(ISNULL(TimesPlayed),0,TimesPlayed) AS Times_Played,
IIF(ISNULL(TimesPlayedByGroupMembers),0,TimesPlayedByGroupMembers) AS Times_Played_By_Group_Members
FROM Games
LEFT JOIN
( SELECT Game_ID,
COUNT(*) AS TimesPlayed,
SUM(IIF(ISNULL(Participation.Played_Games_ID),0,1)) AS TimesPlayedByGroupMembers
FROM Played_Games
LEFT JOIN
( SELECT Played_games_ID
FROM Participation
WHERE Person_ID IN (1, 2)
GROUP BY Played_games_ID
) AS Participation
ON Participation.Played_Games_ID = Played_Games.Played_Games_ID
GROUP BY Game_ID
) AS Played_Games
ON Played_Games.Game_ID = Games.Game_ID
ORDER BY Games.Name
Any help will be greatly appreciated. Thanks for your time!