Hi
I have the following query:
SELECT ft.FantasyTeamID, ft.TeamName, fp.FantasyTeamPlayerID, p.PlayerName, p.PositionID
FROM tblFantasyTeams AS ft, tblFantasyTeamPlayers AS fp, tblPlayers AS p, tblGoals as g
WHERE p.PlayerID = fp.PlayerID AND fp.FantasyTeamID = ft.FantasyTeamID AND ft.FantasyTeamID = @FantasyTeamID
ORDER BY fp.CreationID;
Which gives me a list of fp PlayerID's along with their corresponding Name and Position for a given ft ID. This is correct. But what I would also like to add to this query is a count of all goals in tblGoals for each PlayerID.
I thought the following query should work but when I try it just gives me one record, rather than the list I got before. I think I'm going wrong with the join somewhere. (changes to the above query are in bold below)
SELECT ft.FantasyTeamID, ft.TeamName, fp.FantasyTeamPlayerID, p.PlayerName, p.PositionID,Count(g.GoalID)
FROM tblFantasyTeams AS ft, tblFantasyTeamPlayers AS fp, tblPlayers AS p, tblGoals as g
WHERE p.PlayerID = fp.PlayerID AND fp.FantasyTeamID = ft.FantasyTeamID AND ft.FantasyTeamID = @FantasyTeamID AND g.PlayerID = fp.PlayerID
GROUP BY fp.FantasyTeamPlayerID, ft.FantasyTeamID, ft.TeamName, p.PlayerName, p.PositionID,fp.CreationID
ORDER BY fp.CreationID;
Many thanks for any ideas
P.S Im hoping you don't need to see the structure of all the tables as all the relevant info is contained in the queries above.
Thanks again.
Shaun
I have the following query:
SELECT ft.FantasyTeamID, ft.TeamName, fp.FantasyTeamPlayerID, p.PlayerName, p.PositionID
FROM tblFantasyTeams AS ft, tblFantasyTeamPlayers AS fp, tblPlayers AS p, tblGoals as g
WHERE p.PlayerID = fp.PlayerID AND fp.FantasyTeamID = ft.FantasyTeamID AND ft.FantasyTeamID = @FantasyTeamID
ORDER BY fp.CreationID;
Which gives me a list of fp PlayerID's along with their corresponding Name and Position for a given ft ID. This is correct. But what I would also like to add to this query is a count of all goals in tblGoals for each PlayerID.
I thought the following query should work but when I try it just gives me one record, rather than the list I got before. I think I'm going wrong with the join somewhere. (changes to the above query are in bold below)
SELECT ft.FantasyTeamID, ft.TeamName, fp.FantasyTeamPlayerID, p.PlayerName, p.PositionID,Count(g.GoalID)
FROM tblFantasyTeams AS ft, tblFantasyTeamPlayers AS fp, tblPlayers AS p, tblGoals as g
WHERE p.PlayerID = fp.PlayerID AND fp.FantasyTeamID = ft.FantasyTeamID AND ft.FantasyTeamID = @FantasyTeamID AND g.PlayerID = fp.PlayerID
GROUP BY fp.FantasyTeamPlayerID, ft.FantasyTeamID, ft.TeamName, p.PlayerName, p.PositionID,fp.CreationID
ORDER BY fp.CreationID;
Many thanks for any ideas
P.S Im hoping you don't need to see the structure of all the tables as all the relevant info is contained in the queries above.
Thanks again.
Shaun