0
0
DBMS Theoryknowledge~20 mins

Joins in SQL in DBMS Theory - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SQL Joins Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding INNER JOIN behavior
Given two tables, Employees and Departments, what will be the result of an INNER JOIN on the department ID if some employees do not belong to any department?
DBMS Theory
SELECT Employees.name, Departments.name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.id;
AOnly departments with employees will appear, excluding employees without departments.
BOnly employees who have a matching department will appear in the result.
CAll employees will appear, with NULL for department names if no match exists.
DAll departments will appear, with NULL for employee names if no match exists.
Attempts:
2 left
💡 Hint
Think about what INNER JOIN does when there is no matching record in the other table.
📋 Factual
intermediate
2:00remaining
Identifying LEFT JOIN output
What does a LEFT JOIN return when joining Customers with Orders on customer ID, if some customers have no orders?
DBMS Theory
SELECT Customers.name, Orders.order_id FROM Customers LEFT JOIN Orders ON Customers.id = Orders.customer_id;
AAll orders appear; orders without customers show NULL for customer name.
BOnly customers with orders appear; others are excluded.
CAll customers appear; customers without orders show NULL for order_id.
DOnly customers without orders appear.
Attempts:
2 left
💡 Hint
LEFT JOIN keeps all rows from the left table regardless of matches.
🔍 Analysis
advanced
2:00remaining
Determining output of FULL OUTER JOIN
Consider two tables: Authors and Books. What will a FULL OUTER JOIN on author ID return if some authors have no books and some books have no authors?
DBMS Theory
SELECT Authors.name, Books.title FROM Authors FULL OUTER JOIN Books ON Authors.id = Books.author_id;
AAll authors and all books appear; unmatched authors or books show NULL in the other column.
BOnly authors with books appear; unmatched authors or books are excluded.
COnly books with authors appear; unmatched authors or books are excluded.
DOnly authors without books appear.
Attempts:
2 left
💡 Hint
FULL OUTER JOIN combines LEFT and RIGHT JOIN results.
Comparison
advanced
2:00remaining
Comparing CROSS JOIN and INNER JOIN
What is the main difference between a CROSS JOIN and an INNER JOIN when joining two tables without any ON condition?
DBMS Theory
SELECT * FROM TableA CROSS JOIN TableB;
SELECT * FROM TableA INNER JOIN TableB;
ACROSS JOIN returns the Cartesian product; INNER JOIN without ON is invalid syntax.
BBoth return the Cartesian product of the two tables.
CINNER JOIN returns only matching rows; CROSS JOIN returns all rows from the first table.
DINNER JOIN returns all rows; CROSS JOIN returns only matching rows.
Attempts:
2 left
💡 Hint
Think about the requirement of ON clause in INNER JOIN.
Reasoning
expert
2:00remaining
Predicting number of rows after multiple joins
Given three tables: Students (10 rows), Enrollments (15 rows), and Courses (5 rows). Enrollments links Students and Courses by IDs. If you perform an INNER JOIN of Students to Enrollments, then INNER JOIN the result to Courses, how many rows will the final result have?
DBMS Theory
SELECT Students.name, Courses.title FROM Students INNER JOIN Enrollments ON Students.id = Enrollments.student_id INNER JOIN Courses ON Enrollments.course_id = Courses.id;
A5 rows, equal to the number of courses.
B10 rows, equal to the number of students.
C30 rows, product of students and courses.
D15 rows, equal to the number of enrollments.
Attempts:
2 left
💡 Hint
Enrollments represent each student-course pair; joins filter to matching pairs.