Introduction
INNER JOIN helps you combine rows from two tables when they have matching values in a related column.
SELECT columns FROM table1 INNER JOIN table2 ON table1.common_column = table2.common_column;
SELECT customers.name, orders.order_id FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
SELECT employees.name, departments.department_name FROM employees INNER JOIN departments ON employees.department_id = departments.department_id;
SELECT products.product_name, suppliers.supplier_name FROM products INNER JOIN suppliers ON products.supplier_id = suppliers.supplier_id;
CREATE TABLE customers ( customer_id INT, name VARCHAR(50) ); CREATE TABLE orders ( order_id INT, customer_id INT ); INSERT INTO customers VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie'); INSERT INTO orders VALUES (101, 1), (102, 2), (103, 1); SELECT customers.name, orders.order_id FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id ORDER BY orders.order_id;
INNER JOIN do in MySQL?Employees(id, name, dept_id)Departments(dept_id, dept_name)SELECT Employees.name, Departments.dept_name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.dept_id;
SELECT e.name, d.dept_name FROM Employees e INNER JOIN Departments d ON e.dept_id = d.id;
Orders(order_id, customer_id, amount)Customers(customer_id, name)Pass the test and this pattern moves unknown