176k views
0 votes
You can combine the two steps into a single query with a JOIN.

SELECT
FROM game JOIN goal ON (id=matchid)
The FROM clause says to merge data from the goal table with that from the game table. The ON says how to figure out which rows in game go with which rows in goal - the id from goal must match matchid from game. (If we wanted to be more clear/specific we could say
ON (game.id=goal.matchid)
The code below shows the player (from the goal) and stadium name (from the game table) for every goal scored.
Modify it to show the player, teamid, stadium and mdate and for every German goal

1 Answer

7 votes

Final answer:

To show the player, teamid, stadium, and mdate for every German goal in the database, modify the SQL query to include these fields in the SELECT statement and add a WHERE clause to filter for the German team.

Step-by-step explanation:

To modify the query to show the player, teamid, stadium, and mdate for every German goal, you can include these columns in your SELECT statement. Since you are looking for German goals specifically, you also need to add a WHERE clause to filter the results. Here is what the modified SQL query would look like:

SELECT goal.player, goal.teamid, game.stadium, game.mdate
FROM game
JOIN goal ON game.id = goal.matchid
WHERE goal.teamid = 'GER';

This query merges the game and goal tables where the id from the game matches the matchid from the goal. It then filters the rows to only include those where the teamid is 'GER', which stands for Germany's national football team.

User Florent Georges
by
8.5k points