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.
![](https://www.praudyog.com/wp-content/uploads/2023/04/143.jpg)
(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:
![](https://www.praudyog.com/wp-content/uploads/2023/04/144-1024x258.jpg)
Orders Table:
![](https://www.praudyog.com/wp-content/uploads/2023/04/145-1024x184.jpg)
Example-1:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
Output:
![](https://www.praudyog.com/wp-content/uploads/2023/04/146-1024x221.jpg)
Example-2:
Customer Table:
![](https://www.praudyog.com/wp-content/uploads/2023/04/137-300x189.jpg)
Orders Table:
![](https://www.praudyog.com/wp-content/uploads/2023/04/138-300x213.jpg)
select * from customer
left join product on customer.name = product.customer;
Output:
![](https://www.praudyog.com/wp-content/uploads/2023/04/147-768x323.jpg)