Search code examples
sqlms-access

Can Someone help me write a query to determine which team lost a match AND a separate query to count each teams losses


I have tried the following code.

SELECT  (Team 1) OR ( Team 2) AS[Losser], Winner
FROM MatchesTbl
WHERE (WINNER NOT LIKE (Team 1))

I have attached an image of the table I am working with. I am working in Microsoft access. I am still very new to programming and I am trying to do this for a school project.

Image of Table being used


Solution

  • If you use MS Access you can use the IIF function to get the first result

    SELECT T.Team1, T.Team2, T.Winner, IIf([Team1]=[Winner],[Team2],[Team1]) AS Loser
    FROM tblMatches AS T;
    

    Please note that I modified your orignal table name and field names a little bit.

    In MS Access you can save that query and based on the saved query (I saved it as qryLoser) you can get your second result

    SELECT qryLoser.Loser, Count(qryLoser.Loser) AS CountOfLoser
    FROM qryLoser
    GROUP BY qryLoser.Loser;