Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

SQL query help

  • 19-03-2011 10:34PM
    #1
    Registered Users, Registered Users 2 Posts: 109 ✭✭


    Hi there, I'm having a problem with one of my queries. I'm using MS Access 2007 and I have a query which asks me to:
    'Get the total points scored against a team supplied by the user'.

    My table is as follows after joining two separate tables (TEAM and TEAMPERMATCH):

    teamjointpm.pngthumb_2ea93a52.png

    To create this, I used the following SQL query:
    SELECT *
    FROM TEAM as T INNER JOIN TEAMPERMATCH as TPM on T.TeamID=TPM.TeamID;
    
    What I want to do from here is get the sum of all the points scored against a team whose name the
    user supplies on request of the query. I know what I want to do but I can't seem to form a query around it.
    What I think I am meant to do is select all the matches which the team supplied played in and then get
    all the other teams that played these same matches and sum their scores. I just can't figure out how to write it in a query.

    I don't know if it matters or not but the end aim is to use this query through a Visual Basic program to fill a textbox
    for the total score against a selected team. I have other queries working through VB though so I'm sure it won't be too difficult
    to implemet again.

    Hope someone can help me out :confused:teamjointpm.png
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    SELECT SUM(TeamScore) AS TotalPointsScoredAgainst from TEAM WHERE TEAM.MatchID IN (SELECT MatchID FROM TEAM WHERE TeamName = $UserInput ) AND TEAM.TeamName <> $UserInput
    
    It's not the best because it's written as a subquery and not as sets but subquery->set mapping isn't something I do well after midnight :D


  • Registered Users, Registered Users 2 Posts: 109 ✭✭Barti


    Cheers Sparks, that's exactly what I needed! I was clueless as to how to translate my thoughts into a query but that's brilliant now :D


Advertisement