108k views
4 votes
Which SQL query would you use to retrieve the total number of matches played between all pairs of teams, considering each team plays twice against each other?

a) SELECT COUNT() FROM matches WHERE team1 = team2;
b) SELECT COUNT() FROM matches WHERE team1 != team2;
c) SELECT COUNT(DISTINCT team1, team2) FROM matches;
d) SELECT COUNT(*) FROM matches GROUP BY team1, team2;

User DickieBoy
by
8.8k points

1 Answer

1 vote

Final answer:

The correct SQL query to count the total number of matches played between pairs of teams, with each team playing twice against each other, is option d) SELECT COUNT(*) FROM matches GROUP BY team1, team2.

Step-by-step explanation:

To retrieve the total number of matches played between all pairs of teams, with each team playing twice against each other, the correct SQL query would be option d) SELECT COUNT(*) FROM matches GROUP BY team1, team2. This query will count all the matches and group them by each unique pair of teams. Since each match features two teams, options that involve comparing a team to itself or making distinct pairs without counting them are not appropriate for the given task.

User Richard Hulse
by
7.6k points