Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of using advanced joins in SQL?
Advanced joins help combine data from multiple tables in complex ways to answer detailed questions and get meaningful insights.
Click to reveal answer
intermediate
Explain the difference between INNER JOIN and FULL OUTER JOIN.
INNER JOIN returns only matching rows from both tables. FULL OUTER JOIN returns all rows from both tables, filling with NULLs when there is no match.
Click to reveal answer
intermediate
Why would you use a CROSS JOIN?
CROSS JOIN creates all possible pairs between two tables. It’s useful when you want every combination of rows, like pairing every product with every store.
Click to reveal answer
beginner
How do advanced joins improve data analysis?
They allow combining related data from different tables to see the full picture, find patterns, and answer complex questions that single tables can’t show alone.
Click to reveal answer
advanced
What is a SELF JOIN and when is it useful?
A SELF JOIN joins a table to itself to compare rows within the same table, like finding employees who are managers of others in the same employee list.
Click to reveal answer
Which join returns only rows that have matching values in both tables?
ALEFT JOIN
BINNER JOIN
CFULL OUTER JOIN
DCROSS JOIN
✗ Incorrect
INNER JOIN returns only rows where there is a match in both tables.
What does a FULL OUTER JOIN return?
AAll possible combinations of rows
BAll rows from the left table only
COnly matching rows
DAll rows from both tables, matching where possible
✗ Incorrect
FULL OUTER JOIN returns all rows from both tables, filling with NULLs where there is no match.
When would you use a SELF JOIN?
ATo compare rows within the same table
BTo filter rows based on a condition
CTo get all combinations of two tables
DTo combine two different tables
✗ Incorrect
SELF JOIN is used to join a table to itself to compare rows within that table.
Which join type creates every possible pair of rows between two tables?
AINNER JOIN
BLEFT JOIN
CCROSS JOIN
DRIGHT JOIN
✗ Incorrect
CROSS JOIN returns the Cartesian product of the two tables, pairing every row from the first with every row from the second.
Why are advanced joins important in databases?
AThey allow combining data from multiple tables in complex ways
BThey speed up simple queries
CThey delete duplicate data
DThey create new tables automatically
✗ Incorrect
Advanced joins let you combine data from multiple tables to answer complex questions and get deeper insights.
Describe how advanced joins help in combining data from multiple tables and why this matters.
Think about how different tables hold different pieces of information and how joins bring them together.
You got /4 concepts.
Explain the difference between INNER JOIN, LEFT JOIN, and FULL OUTER JOIN with simple examples.
Imagine two lists of friends and how you want to see who is in both, only in one, or in either list.
You got /4 concepts.
Practice
(1/5)
1. Which type of SQL join returns only the rows that have matching values in both tables?
easy
A. INNER JOIN
B. LEFT JOIN
C. RIGHT JOIN
D. FULL JOIN
Solution
Step 1: Understand INNER JOIN behavior
INNER JOIN returns rows where the join condition matches in both tables, excluding unmatched rows.
Step 2: Compare with other joins
LEFT JOIN returns all rows from the left table, RIGHT JOIN from the right, and FULL JOIN all rows from both tables, including unmatched ones.
Final Answer:
INNER JOIN -> Option A
Quick Check:
Matching rows only = INNER JOIN [OK]
Hint: INNER JOIN = only matched rows from both tables [OK]
Common Mistakes:
Confusing LEFT JOIN with INNER JOIN
Thinking FULL JOIN returns only matched rows
Assuming RIGHT JOIN excludes unmatched rows
2. Which of the following is the correct syntax to perform a LEFT JOIN between tables employees and departments on employees.dept_id = departments.id?
easy
A. SELECT * FROM employees JOIN departments ON employees.dept_id = departments.id LEFT;
B. SELECT * FROM employees JOIN departments WHERE employees.dept_id = departments.id LEFT;
C. SELECT * FROM employees LEFT JOIN departments WHERE employees.dept_id = departments.id;
D. SELECT * FROM employees LEFT JOIN departments ON employees.dept_id = departments.id;
Solution
Step 1: Identify correct JOIN syntax
The correct syntax for LEFT JOIN uses the ON keyword to specify join condition: LEFT JOIN table ON condition.
Step 2: Check each option
SELECT * FROM employees LEFT JOIN departments ON employees.dept_id = departments.id; uses correct syntax. Options B and D misuse WHERE or place LEFT incorrectly. SELECT * FROM employees LEFT JOIN departments WHERE employees.dept_id = departments.id; uses WHERE instead of ON.
Final Answer:
SELECT * FROM employees LEFT JOIN departments ON employees.dept_id = departments.id; -> Option D
Quick Check:
LEFT JOIN requires ON, not WHERE [OK]
Hint: Use ON for join condition, not WHERE in JOIN syntax [OK]
Common Mistakes:
Using WHERE instead of ON for join condition
Placing LEFT keyword after JOIN incorrectly
Omitting ON clause in JOIN
3. Given tables orders and customers, what will the following query return?
SELECT customers.name, orders.id FROM customers LEFT JOIN orders ON customers.id = orders.customer_id WHERE orders.id IS NULL;
medium
A. All customers who have not placed any orders
B. All customers who have placed at least one order
C. All orders without a matching customer
D. All customers and their orders
Solution
Step 1: Analyze LEFT JOIN with WHERE condition
The LEFT JOIN returns all customers with matching orders or NULL if no order exists. The WHERE clause filters rows where orders.id is NULL, meaning no matching order.
Step 2: Interpret the result
This query returns customers who have no orders because orders.id is NULL for them.
Final Answer:
All customers who have not placed any orders -> Option A
Quick Check:
LEFT JOIN + WHERE orders.id IS NULL = customers without orders [OK]
Hint: LEFT JOIN + WHERE right table column IS NULL finds missing matches [OK]
Common Mistakes:
Thinking it returns customers with orders
Confusing NULL in orders.id with existing orders
Assuming it returns unmatched orders
4. Consider this SQL query:
SELECT a.id, b.value FROM tableA a RIGHT JOIN tableB b ON a.id = b.a_id WHERE a.id > 10;
What is the main issue with this query?
medium
A. RIGHT JOIN syntax is incorrect; it should be LEFT JOIN
B. The WHERE clause filters out rows where a.id is NULL, negating the RIGHT JOIN effect
C. The ON condition is invalid because columns have different names
D. The query will cause a syntax error due to aliasing
Solution
Step 1: Understand RIGHT JOIN with WHERE filter
RIGHT JOIN returns all rows from tableB and matching from tableA. Rows with no match have NULL in a.id.
Step 2: Effect of WHERE a.id > 10
The WHERE clause excludes rows where a.id is NULL, removing unmatched rows from tableB, which defeats the purpose of RIGHT JOIN.
Final Answer:
The WHERE clause filters out rows where a.id is NULL, negating the RIGHT JOIN effect -> Option B
Quick Check:
Filtering NULLs after RIGHT JOIN removes unmatched rows [OK]
Hint: Filter NULLs in JOIN condition, not WHERE, to keep unmatched rows [OK]
Common Mistakes:
Thinking RIGHT JOIN syntax is wrong
Ignoring NULL filtering effect in WHERE
Assuming aliasing causes error
5. You have two tables: students (id, name) and enrollments (student_id, course). You want to list all students and the courses they are enrolled in, including students with no enrollments. Which SQL query correctly achieves this?
hard
A. SELECT students.name, enrollments.course FROM students INNER JOIN enrollments ON students.id = enrollments.student_id;
B. SELECT students.name, enrollments.course FROM enrollments LEFT JOIN students ON students.id = enrollments.student_id;
C. SELECT students.name, enrollments.course FROM students LEFT JOIN enrollments ON students.id = enrollments.student_id;
D. SELECT students.name, enrollments.course FROM students RIGHT JOIN enrollments ON students.id = enrollments.student_id;
Solution
Step 1: Identify requirement for all students
We want all students listed, even those without enrollments, so the join must keep all rows from students.
Step 2: Choose correct join type
LEFT JOIN keeps all rows from the left table (students) and matches enrollments if any. INNER JOIN excludes students without enrollments. RIGHT JOIN would keep all enrollments, not students.
Final Answer:
SELECT students.name, enrollments.course FROM students LEFT JOIN enrollments ON students.id = enrollments.student_id; -> Option C
Quick Check:
LEFT JOIN keeps all left table rows (students) [OK]
Hint: Use LEFT JOIN to keep all from first table, even if no match [OK]
Common Mistakes:
Using INNER JOIN excludes students without courses
Using RIGHT JOIN keeps all enrollments, not students