SQL Joins · Question 16 · Hard

SQL Joins question 16

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

Table Awards:
award | player_id
Orange Cap | 4
Purple Cap | 2
Emerging Player | 6

How many rows does this query return?

SELECT t.team, p.name, a.award
FROM Teams t
LEFT JOIN Players p ON t.team_id = p.team_id
JOIN Awards a ON a.player_id = p.player_id;
  1. 2 rows
  2. 3 rows
  3. 5 rows
  4. 6 rows
Answer and explanation

Answer: A. 2 rows

Explanation: The left join gives 5 rows, including GT with a NULL player. The inner join to Awards then needs a matching p.player_id, so GT's NULL row is dropped and only Bala (Purple Cap) and Dinesh (Orange Cap) survive. Farid has an award but was never in the left-join result.

Previous: Tables Authors(author_id, name) and Books(book_id, title, author_id) exist… · Next: Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id…

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