-
MySql Query 3 tables
I'm having some trouble building this MySql query. I need to get all the tblScoreRel.userIds in order of the sum(tblscores.points) where tblGames.weekNo < x > Y.
The tables are set up as follows
tblGames
weekNo
tblScores
points
scoreId
gameID (Links to tblGames.id)
tblScoreRel
userId
scoreId (links to tblScores.Id
Hope that makes some sense?
-
Re: MySql Query 3 tables
I am not exactly sure what you want in the where clause but I am sure that you can modify this to suit your needs.
Code:
SELECT weekNo FROM tblGames
INNER JOIN tblScores ON tblGames.id = tblScores.gameId
INNER JOIN tblScoreRel ON tblGames.id = tblScoreRel.scoreId
WHERE tblGames.weekNo = ?
Hope this helps:)
-
Re: MySql Query 3 tables
Off the top of my head... :) Let me know if it works.
Code:
SELECT
SUM(t1.points) total_points,
t1.userid
FROM
tblGames,
(
SELECT
userid,
scoreid,
gameid,
points
FROM
tblScoreRel,
tblScores
WHERE
tblScoreRel.scoreid = tblScores.scoreid
) t1
WHERE
tblGames.gameid = t1.gameid
AND tblGames.weekno = 10
GROUP BY
t1.userid
ORDER BY
total_points desc