SQL Joins · Question 13 · Medium

SQL Joins question 13

Table Riders:
rider_id | name
1 | Manoj
2 | Nisha
3 | Om

Table Trips:
trip_id | rider_id | fare | status
1 | 1 | 120 | DONE
2 | 1 | 80 | CANCELLED
3 | 2 | 200 | CANCELLED

How many rows does this query return?

SELECT r.name, t.fare
FROM Riders r
LEFT JOIN Trips t ON r.rider_id = t.rider_id
WHERE t.status = 'DONE';
  1. 1 row
  2. 2 rows
  3. 3 rows
  4. 4 rows
Answer and explanation

Answer: A. 1 row

Explanation: The left join gives 4 rows (Manoj twice, Nisha once, Om with NULLs). WHERE runs after the join and keeps only rows whose status is DONE, so Om's NULL row and the cancelled trips are removed and only Manoj, 120 remains.

Previous: Table Staff: emp_id | name | manager_id 1 | Nandini | NULL 2 | Omkar | 1 3 |… · 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