Geek Slack

My SQL Tutorial
    About Lesson


    MySQL LEFT JOIN Keyword


    MySQL LEFT JOIN Keyword

    The LEFT JOIN keyword in MySQL returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side if there is no match.

    Example:

    SELECT customers.customer_name, orders.order_id
    FROM customers
    LEFT JOIN orders ON customers.customer_id = orders.customer_id;

    This query retrieves customer names along with their order IDs, including customers who have not placed any orders.

    The LEFT JOIN keyword is useful for retrieving all records from one table along with matching records from another table, even if there are no matches.