Ira SQL ProIra SQL Pro

SQL INNER JOIN

beginnerjoins
2 min read

What is INNER JOIN?

INNER JOIN returns rows that have matching values in both tables. If a row in one table has no match in the other, it is excluded from the result.

Syntax

SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;

When to Use

  • Fetching related data from two tables (students and their enrollments)
  • When you only want records that exist in both tables
  • Replacing subqueries for better readability

Key Points

  1. Only Matches — Rows without a match in either table are excluded.
  2. ON Clause — Specifies the join condition. Usually matches a foreign key to a primary key.
  3. USING Clause — If both tables share a column name, you can use USING (column_name) instead of ON.
  4. Multiple Conditions — You can have compound join conditions: ON t1.a = t2.a AND t1.b = t2.b.
  5. Performance — Ensure join columns are indexed for optimal performance.
  6. Default JOIN — Writing JOIN without a prefix defaults to INNER JOIN.

Guided Practice

Solve the challenge below. Use hints when stuck and check your answer for instant feedback.

Practice challengeGuided learning mode

SQL INNER JOIN Challenge

Write a query that solve this task: get each student along with their enrollment records.

Expected result

One row per enrollment showing the student name, course ID, and enrollment date. Students with no enrollments are excluded.

Hidden checks

  • Returned rows and values
  • Output columns and result shape
  • Final database state after the query runs

Lesson guidance

What is INNER JOIN?

Initializing database...Each run starts from fresh sample data.

More Examples

Join orders and products

Show order details with product names.

Initializing database...Each run starts from fresh sample data.

Frequently Asked Questions

What is the difference between JOIN and INNER JOIN?
They are identical. JOIN defaults to INNER JOIN. Writing INNER JOIN is more explicit and recommended for clarity.
Can I join on multiple columns?
Yes. Use AND in the ON clause: ON t1.col_a = t2.col_a AND t1.col_b = t2.col_b.

Related Topics