Results 1 to 3 of 3

Thread: MySql Query 3 tables

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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?

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    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
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width