Using the sports database containing two relations (TEAM, MATCH_DETAILS) and write the queries for the following: Display the MatchID and date of matches played by Team 1 and won by it.
SELECT MatchID, MatchDate FROM MATCH_DETAILS WHERE (FirstTeamID = 1 AND FirstTeamScore > SecondTeamScore) OR (SecondTeamID = 1 AND SecondTeamScore > FirstTeamScore);
Explanation
To display matches played by Team 1 and won by it, we need to check two conditions: (1) When Team 1 is the FirstTeamID, it wins if FirstTeamScore > SecondTeamScore, and (2) When Team 1 is the SecondTeamID, it wins if SecondTeamScore > FirstTeamScore. Both conditions are combined using OR operator. From the table data, M1 (2018-07-17) and M3 (2018-07-19) are matches where Team 1 played and won.
Solution Steps
Step 1: Identify columns to display - MatchID and MatchDate
Step 2: Identify the table - MATCH_DETAILS
Step 3: Form condition for Team 1 playing - FirstTeamID = 1 OR SecondTeamID = 1
Step 4: Add winning condition - If FirstTeamID = 1, then FirstTeamScore > SecondTeamScore; If SecondTeamID = 1, then SecondTeamScore > FirstTeamScore
Step 5: Combine conditions using OR operator with proper parentheses