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 does INNER JOIN do in SQL?
INNER JOIN combines rows from two tables where the join condition is true, returning only matching rows.
Click to reveal answer
beginner
Write the basic syntax of an INNER JOIN between two tables table1 and table2 on a common column id.
SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
Click to reveal answer
beginner
Can INNER JOIN return rows where there is no match in the other table?
No, INNER JOIN only returns rows where there is a match in both tables based on the join condition.
Click to reveal answer
intermediate
What happens if you omit the ON clause in an INNER JOIN?
Omitting the ON clause causes a syntax error because the join condition is required to match rows.
Click to reveal answer
intermediate
How is INNER JOIN different from LEFT JOIN?
INNER JOIN returns only matching rows from both tables, while LEFT JOIN returns all rows from the left table and matching rows from the right table (or NULL if no match).
Click to reveal answer
What does INNER JOIN return?
AAll rows from both tables
BAll rows from the left table
CAll rows from the right table
DOnly rows with matching values in both tables
✗ Incorrect
INNER JOIN returns only rows where the join condition matches in both tables.
Which keyword is mandatory in an INNER JOIN to specify how tables are matched?
AWHERE
BUSING
CON
DGROUP BY
✗ Incorrect
The ON clause specifies the join condition for INNER JOIN.
What happens if there is no matching row in the second table for an INNER JOIN?
AThe row is included with NULLs
BThe row is excluded from the result
CAn error is thrown
DThe row is duplicated
✗ Incorrect
INNER JOIN excludes rows without matches in the other table.
Which SQL clause can be used as a shorthand for INNER JOIN when joining on columns with the same name?
AUSING
BON
CWHERE
DGROUP BY
✗ Incorrect
USING can be used to join tables on columns with the same name.
Which of the following is a valid INNER JOIN syntax?
ASELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
BSELECT * FROM table1 JOIN table2 WHERE table1.id = table2.id;
CSELECT * FROM table1 INNER JOIN table2 USING table1.id = table2.id;
DSELECT * FROM table1 INNER JOIN table2;
✗ Incorrect
Option A is the correct syntax with INNER JOIN and ON clause.
Explain how INNER JOIN works and write a simple query joining two tables on a common column.
Think about matching rows in two lists and how you combine them.
You got /3 concepts.
Describe the difference between INNER JOIN and LEFT JOIN with an example scenario.
Imagine two lists of friends and which friends appear in both or only one list.
You got /3 concepts.
Practice
(1/5)
1. What does an INNER JOIN do in SQL?
easy
A. It returns all rows from the first table only.
B. It returns rows that have matching values in both tables.
C. It returns all rows from the second table only.
D. It returns all rows from both tables, matching or not.
Solution
Step 1: Understand the purpose of INNER JOIN
INNER JOIN combines rows from two tables where the join condition matches in both tables.
Step 2: Compare options with INNER JOIN behavior
Only the description "It returns rows that have matching values in both tables." correctly states that it returns rows with matching values in both tables.
Final Answer:
It returns rows that have matching values in both tables. -> Option B
Quick Check:
INNER JOIN = matching rows only [OK]
Hint: INNER JOIN returns only matching rows from both tables [OK]
Common Mistakes:
Thinking INNER JOIN returns all rows from one table
Confusing INNER JOIN with LEFT or RIGHT JOIN
Assuming it returns unmatched rows
2. Which of the following is the correct syntax for an INNER JOIN between tables Employees and Departments on the column DeptID using the ON clause?
easy
A. SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID == Departments.DeptID;
B. SELECT * FROM Employees JOIN Departments WHERE Employees.DeptID = Departments.DeptID;
C. SELECT * FROM Employees INNER JOIN Departments USING DeptID;
D. SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
Solution
Step 1: Review INNER JOIN syntax
The correct syntax uses INNER JOIN with ON and a single equals sign (=) for comparison.
Step 2: Check each option
SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID; uses correct INNER JOIN syntax with ON and =. SELECT * FROM Employees JOIN Departments WHERE Employees.DeptID = Departments.DeptID; uses WHERE instead of ON. SELECT * FROM Employees INNER JOIN Departments USING DeptID; uses USING instead of ON. SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID == Departments.DeptID; uses double equals (==), which is not valid in SQL.
Final Answer:
SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID; -> Option D
Quick Check:
INNER JOIN syntax = ON with single = [OK]
Hint: Use ON with single = for INNER JOIN conditions [OK]
Common Mistakes:
Using WHERE instead of ON for join condition
Using double equals (==) instead of single equals (=)
Using USING instead of ON
3. Given the tables: Employees(id, name, dept_id) Departments(dept_id, dept_name) What is the result of this query?
SELECT name, dept_name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.dept_id;
B. [('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', '30')]
C. [('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', NULL)]
D. [('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', 'Finance')]
Solution
Step 1: Identify matching rows by dept_id
Employees with dept_id 10 and 20 match Departments with same dept_id. Carol's dept_id 30 has no match.
Step 2: Understand INNER JOIN output
INNER JOIN returns only rows with matching dept_id in both tables, so Carol is excluded.
Final Answer:
[('Alice', 'HR'), ('Bob', 'Sales')] -> Option A
Quick Check:
INNER JOIN excludes unmatched rows [OK]
Hint: INNER JOIN excludes rows without matching keys [OK]
Common Mistakes:
Including unmatched rows in result
Assuming NULL values appear for unmatched rows
Confusing INNER JOIN with LEFT JOIN behavior
4. Identify the error in this SQL query:
SELECT e.name, d.dept_name FROM Employees e INNER JOIN Departments d ON e.dept_id == d.dept_id;
medium
A. The join condition uses '==' instead of '='.
B. Using alias names for tables is not allowed.
C. Missing WHERE clause for filtering.
D. INNER JOIN requires USING instead of ON.
Solution
Step 1: Check join condition syntax
SQL uses a single equals sign (=) for comparison, not double equals (==).
Step 2: Verify other parts of the query
Aliases e and d are valid. WHERE clause is optional. INNER JOIN can use ON.
Final Answer:
The join condition uses '==' instead of '='. -> Option A
Quick Check:
Use = for join conditions, not == [OK]
Hint: Use single = in ON clause, not double == [OK]
Common Mistakes:
Using == instead of = in join condition
Thinking aliases are disallowed
Confusing ON with WHERE clause necessity
5. You have two tables: Orders(order_id, customer_id, amount) Customers(customer_id, customer_name) You want to find all customers who have placed orders and the total amount they spent. Which query correctly uses INNER JOIN and aggregation to get this result?
hard
A. SELECT c.customer_name, SUM(o.amount) AS total_spent FROM Customers c LEFT JOIN Orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name;
B. SELECT c.customer_name, o.amount FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id;
C. SELECT c.customer_name, SUM(o.amount) AS total_spent FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name;
D. SELECT customer_name, amount FROM Customers INNER JOIN Orders ON customer_id = customer_id;
Solution
Step 1: Understand the requirement
We want customers who placed orders and the total amount spent, so INNER JOIN with aggregation is needed.
Step 2: Analyze each option
SELECT c.customer_name, SUM(o.amount) AS total_spent FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name; correctly uses INNER JOIN on customer_id and sums amounts grouped by customer_name. SELECT c.customer_name, SUM(o.amount) AS total_spent FROM Customers c LEFT JOIN Orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name; uses LEFT JOIN, which includes customers without orders. SELECT c.customer_name, o.amount FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id; does not aggregate amounts. SELECT customer_name, amount FROM Customers INNER JOIN Orders ON customer_id = customer_id; has ambiguous join condition and no aggregation.
Final Answer:
SELECT c.customer_name, SUM(o.amount) AS total_spent FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name; -> Option C
Quick Check:
INNER JOIN + GROUP BY + SUM = total spent per customer [OK]
Hint: Use INNER JOIN with GROUP BY and SUM for totals [OK]
Common Mistakes:
Using LEFT JOIN instead of INNER JOIN when only matching rows needed