Writing a Basic INNER JOIN Query in MySQL
An INNER JOIN returns only the rows where there is a matching value in both tables. It is the most commonly used type of JOIN in SQL.
SELECT columns
FROM table1
INNER JOIN table2 ON table1.common_column = table2.common_column;
Suppose you have two tables:
• users (id, name)
• orders (id, user_id, amount)
Query:
SELECT u.id, u.name, o.amount
FROM users u
INNER JOIN orders o ON u.id = o.user_id;
• This returns only the users who have placed at least one order.
Use INNER JOIN when you want to fetch only the matching records from both tables.