SQL Joins · Question 6 · Easy
SQL Joins question 6
Table Staff:
emp_id | name | manager_id
1 | Nandini | NULL
2 | Omkar | 1
3 | Pallavi | 1
4 | Qasim | 2
5 | Ritu | 2
manager_id refers to emp_id in the same table. What does this query return?
SELECT e.name, m.name
FROM Staff e
JOIN Staff m ON e.manager_id = m.emp_id
WHERE e.emp_id = 4;
- Qasim, Nandini
- Omkar, Qasim
- Qasim, Omkar
- Qasim, NULL
Answer and explanation
Answer: C. Qasim, Omkar
Explanation: In this self join, e is the employee and m is the manager row. Qasim has manager_id 2, and emp_id 2 is Omkar.
Previous: Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |… · Next: Which of these is equivalent to A RIGHT JOIN B ON A.k = B.k (ignoring column…
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
- Table Colours: colour Red Blue Green Table Sizes: size S M How many rows does…
- In A LEFT JOIN B, what happens to a row of A that has no matching row in B?
- Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…
- Which of these is equivalent to A RIGHT JOIN B ON A.k = B.k (ignoring column…
- Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…
- Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…
- Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…
- Table Learners: name | city Isha | Delhi Jatin | Delhi Kiran | Pune Leela |…
- Table Staff: emp_id | name | manager_id 1 | Nandini | NULL 2 | Omkar | 1 3 |…
- Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id…
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