SQL Joins · Question 10 · Medium

SQL Joins question 10

Table Teams:
team_id | team | city
1 | CSK | Chennai
2 | MI | Mumbai
3 | RCB | Bengaluru
4 | GT | Ahmedabad

Table Players:
player_id | name | team_id
1 | Ajay | 1
2 | Bala | 1
3 | Chetan | 2
4 | Dinesh | 3
5 | Eshan | NULL
6 | Farid | 7

What does this query return?

SELECT COUNT(t.team_id), COUNT(p.player_id)
FROM Teams t
FULL JOIN Players p ON t.team_id = p.team_id;
  1. 5, 6
  2. 7, 7
  3. 4, 4
  4. 4, 6
Answer and explanation

Answer: A. 5, 6

Explanation: The full join has 7 rows: 4 matches, GT alone, and Eshan and Farid alone. COUNT(col) skips NULLs, so t.team_id is counted in 4 + 1 = 5 rows and p.player_id in 4 + 2 = 6 rows.

Previous: Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |… · Next: Table Learners: name | city Isha | Delhi Jatin | Delhi Kiran | Pune Leela |…

Practise sql joins

Try a fresh set of sql joins questions with an explanation after every answer, free and without signing up: SQL Joins practice. Or sit a full placement mock test.

More sql joins questions

More sql practice

Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge