SQL joins are used to combine rows from two or more tables based on a related column. Understanding the type of join is crucial for controlling which records are included in the result.
NULL.NULL.NULL.Use the appropriate join type depending on whether you want to include unmatched rows and from which table(s). This is especially helpful for reports, audits, and merging data from multiple sources.
Returns only employees that belong to a department.
SELECT employees.name, departments.name
FROM employees
INNER JOIN departments
ON employees.dept_id = departments.id;Returns all customers, even if they have no orders (NULL for unmatched orders).
SELECT customers.name, orders.id
FROM customers
LEFT JOIN orders
ON customers.id = orders.customer_id;Returns all suppliers, including those who have no products listed.
SELECT products.name, suppliers.name
FROM products
RIGHT JOIN suppliers
ON products.supplier_id = suppliers.id;Returns all authors and books, with NULLs where no match exists.
SELECT a.name, b.title
FROM authors a
FULL OUTER JOIN books b
ON a.id = b.author_id;AS a) to make queries cleanerONIS NULL to filter unmatched rows when neededAsk the AI if you need help understanding or want to dive deeper in any topic