SQL – Left Join
Table Of Content:
- What Is SQL Left Join?
- Syntax Of SQL Left Join.
- Examples Of SQL Left Join.
(1) What Is SQL Left Join?
- The
LEFT JOIN
keyword returns all records from the left table (table1), and the matching records from the right table (table2). The result is 0 records from the right side if there is no match.
(2) Syntax Of SQL Left Join.
Syntax:
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
(3) Examples Of SQL Left Join.
Customer Table:
Orders Table:
Example-1:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
Output:
Example-2:
Customer Table:
Orders Table:
select * from customer
left join product on customer.name = product.customer;