Introduction
Joins help combine data from two or more tables into one result. This lets you see related information together easily.
Joins help combine data from two or more tables into one result. This lets you see related information together easily.
SELECT columns FROM table1 JOIN table2 ON table1.common_column = table2.common_column;
SELECT customers.name, orders.order_date FROM customers JOIN orders ON customers.id = orders.customer_id;
SELECT employees.name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.id;
SELECT products.product_name, suppliers.supplier_name FROM products JOIN suppliers ON products.supplier_id = suppliers.id;
This example creates two tables, adds data, and joins them to show customer names with their order dates.
CREATE TABLE customers (id INT, name TEXT); CREATE TABLE orders (id INT, customer_id INT, order_date DATE); INSERT INTO customers VALUES (1, 'Alice'), (2, 'Bob'); INSERT INTO orders VALUES (101, 1, '2024-06-01'), (102, 2, '2024-06-02'); SELECT customers.name, orders.order_date FROM customers JOIN orders ON customers.id = orders.customer_id;
Joins let you combine related data without repeating information in one table.
Without joins, you would need to look at each table separately and match data manually.
Joins combine data from multiple tables based on a common column.
They help you see related information together in one result.
Using joins makes data analysis easier and more efficient.
employees and departments on the column department_id?students(id, name)grades(student_id, score)SELECT students.name, grades.score FROM students JOIN grades ON students.id = grades.student_id;
SELECT e.name, d.name FROM employees e JOIN departments d ON e.dept_id = d.idd;
orders(order_id, customer_id, amount)customers(customer_id, name)Pass the test and this pattern moves unknown