SQL Joins · Question 2 · Easy

SQL Joins question 2

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 t.team, p.name
FROM Teams t
JOIN Players p ON t.team_id = p.team_id
WHERE t.city = 'Chennai'
ORDER BY p.name;
  1. CSK, Ajay; CSK, Bala
  2. CSK, Ajay
  3. Chennai, Ajay; Chennai, Bala
  4. CSK, Ajay; CSK, Bala; MI, Chetan
Answer and explanation

Answer: A. CSK, Ajay; CSK, Bala

Explanation: The join pairs each player with the team whose team_id matches, and WHERE keeps the Chennai team only. CSK has two players, so its row appears twice, once per player.

Previous: Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |… · Next: Table Colours: colour Red Blue Green Table Sizes: size S M How many rows does…

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