0
0
PostgreSQLquery~20 mins

INNER JOIN execution in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
INNER JOIN Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of INNER JOIN with matching keys
Given two tables Employees and Departments, what is the output of the following query?
SELECT Employees.name, Departments.department_name FROM Employees INNER JOIN Departments ON Employees.department_id = Departments.id;

Assume:
Employees: (id:1, name:'Alice', department_id:10), (id:2, name:'Bob', department_id:20), (id:3, name:'Charlie', department_id:30)
Departments: (id:10, department_name:'HR'), (id:20, department_name:'Finance')
PostgreSQL
SELECT Employees.name, Departments.department_name FROM Employees INNER JOIN Departments ON Employees.department_id = Departments.id;
A[{"name": "Alice", "department_name": "HR"}, {"name": "Bob", "department_name": "Finance"}]
B[{"name": "Alice", "department_name": "HR"}, {"name": "Bob", "department_name": "Finance"}, {"name": "Charlie", "department_name": null}]
C[{"name": "Charlie", "department_name": "HR"}]
D[]
Attempts:
2 left
💡 Hint
INNER JOIN returns rows where the join condition matches in both tables.
🧠 Conceptual
intermediate
1:30remaining
Understanding INNER JOIN behavior
Which statement best describes the behavior of an INNER JOIN between two tables?
AIt returns all rows from the second table and matching rows from the first table, including unmatched rows as NULLs.
BIt returns all rows from the first table and matching rows from the second table, including unmatched rows as NULLs.
CIt returns all rows from both tables, combining them regardless of matching values.
DIt returns only rows where there is a matching value in both tables based on the join condition.
Attempts:
2 left
💡 Hint
Think about which rows appear when both tables have matching keys.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in INNER JOIN query
Which option contains a syntax error in the INNER JOIN query?
PostgreSQL
SELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d ON e.department_id = d.id;
ASELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d ON e.department_id = d.id ORDER BY e.name;
BSELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d ON e.department_id = d.id LIMIT 5;
CSELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d WHERE e.department_id = d.id;
DSELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d ON e.department_id = d.id;
Attempts:
2 left
💡 Hint
INNER JOIN requires ON clause for join condition, not WHERE.
optimization
advanced
2:00remaining
Optimizing INNER JOIN performance
Which option is the best way to optimize INNER JOIN performance on large tables?
AAdd indexes on the columns used in the join condition in both tables.
BUse a CROSS JOIN instead of INNER JOIN for faster results.
CUse SELECT * to retrieve all columns to avoid specifying columns.
DAvoid using WHERE clause filters after the INNER JOIN.
Attempts:
2 left
💡 Hint
Indexes help the database find matching rows faster.
🔧 Debug
expert
2:30remaining
Diagnose unexpected INNER JOIN result
A query uses INNER JOIN between tables Orders and Customers on Customers.id = Orders.customer_id. The result is empty, but both tables have data. What is the most likely cause?
AThe database engine does not support INNER JOIN.
BThe join condition uses wrong columns or mismatched data types causing no matches.
CINNER JOIN always returns empty if one table has more rows than the other.
DThe SELECT statement is missing a WHERE clause to filter rows.
Attempts:
2 left
💡 Hint
Check if the join columns actually match and have compatible data types.