SQL Exercise: Bottom of their groups and conceded 4 goals in 3 games
SQL soccer Database: Joins Exercise-28 with Solution
28. From the following tables, write a SQL query to find which teams finished at the bottom of their respective groups after conceding four goals in three games. Return country name, team group and match played.
Sample table: soccer_team
Sample table: soccer_country
Sample Solution:
SQL Code:
SELECT a.country_name as Team , b.team_group,b.match_played,
b.goal_agnst, b.group_position
FROM soccer_country a
JOIN soccer_team b
ON a.country_id=b.team_id
WHERE goal_agnst=4 AND group_position=4
ORDER BY team_group;
Sample Output:
team | team_group | match_played | goal_agnst | group_position ---------+------------+--------------+------------+---------------- Romania | A | 3 | 4 | 4 Austria | F | 3 | 4 | 4 (2 rows)
Code Explanation:
The said query in SQL which selects the country name, team group, match played, goals against, and group position from the tables 'soccer_country' and 'soccer_team'.
The WHERE clause filters the results to only include teams that have conceded four goals and finished fourth in their respective groups, then orders the results by team group.
Relational Algebra Expression:

Relational Algebra Tree:

Practice Online
Sample Database: soccer

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Two teams that scored three goals in a single game.
Next SQL Exercise: Find 3 Lyon players participated in the EURO Finals.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
What is the best way to paginate results in SQL Server?
SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, * FROM Orders WHERE OrderDate >= '1980-01-01' ) AS RowConstrainedResult WHERE RowNum >= 1 AND RowNum < 20 ORDER BY RowNum
Database: SQL Server
Ref: https://bit.ly/3MGrNlk
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook