SQL Beginner Challenge 8: Join Two Tables with INNER JOIN

Difficulty: Beginner
Estimated time: 15–20 minutes
SQL concepts: INNER JOIN, joining tables, foreign keys
Goal: Combine data from multiple tables into one result.

The Scenario

So far, all queries have used a single table.
In real databases, information is usually split across multiple related tables.

A product manager now asks:

“Show me each product along with its supplier name.”

That information lives in two tables, so you need to join them.

Database Tables

products

column_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price
supplier_idINTEGERReferences suppliers.supplier_id

suppliers

column_nametypedescription
supplier_idINTEGERUnique supplier ID
supplier_nameTEXTSupplier name

Sample Data

products

product_idnamecategorypricesupplier_id
101Wireless MouseAccessories24.991
102Mechanical KeyboardAccessories89.001
10327-inch MonitorDisplays229.992
104USB-C HubAccessories34.503
105Laptop StandWorkspace39.992

suppliers

supplier_idsupplier_name
1TechSource
2DisplayWorks
3GadgetCo

Your Task

Write a SQL query that returns:

  • Product name
  • supplier_name

For all products that have a matching supplier.

Expected Output

namesupplier_name
Wireless MouseTechSource
Mechanical KeyboardTechSource
27-inch MonitorDisplayWorks
USB-C HubGadgetCo
Laptop StandDisplayWorks

Constraints

  • Use INNER JOIN
  • Join products and suppliers using supplier_id
  • Return only the requested columns
  • Do not use SELECT *

Hint (Optional)

An INNER JOIN returns only rows where the join condition matches in both tables.

SELECT
p.name,
s.supplier_name
FROM products p
INNER JOIN suppliers s
ON p.supplier_id = s.supplier_id;

Explanation

  • INNER JOIN combines rows from both tables where the IDs match.
  • Table aliases (p, s) make queries easier to read.
  • Only products with a valid supplier are returned.

Common Mistakes

  1. Forgetting the join condition
    FROM products p, suppliers s -- ❌ creates a cartesian product
  2. Joining on the wrong column
  3. Using SELECT * in joins

Optional Extension (Mini Bonus)

Try:

  1. Add product price to the result.
  2. Filter results to only Accessories.
  3. Sort products by supplier name.

Next Challenge

Beginner Challenge #9: Keep All Products with LEFT JOIN

🔗 View reference solution on GitHub
(After you’ve tried the challenge)

Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.