SQL Joins

Learn how to combine data from multiple tables in SQL using joins.

Understanding Joins

SQL joins are used to combine rows from two or more tables based on a related column. There are different types of joins, each with a specific purpose:

Examples

Here are some examples of how to use joins:


            -- Example: Combining Customers and Orders
            SELECT
                c.CustomerID,
                c.CustomerName,
                o.OrderID,
                o.OrderDate
            FROM
                Customers c
            INNER JOIN
                Orders o ON c.CustomerID = o.CustomerID;
            

            -- Example: Using a LEFT JOIN to get all customers and their orders
            SELECT
                c.CustomerID,
                c.CustomerName,
                o.OrderID,
                o.OrderDate
            FROM
                Customers c
            LEFT JOIN
                Orders o ON c.CustomerID = o.CustomerID;
            

Related Resources