You are on page 1of 3

SQL LEFT JOIN

SQL LEFT JOIN returns all the rows from the left table mentioned with the LEFT JOIN
clause. If there are no matching rows in right table then output rows will return NULL
values.

Syntax
SELECT columnName(s)
FROM Table1 LEFT JOIN Table2
ON Table1.columnName = Table2.columnName
Refer below image to understand LEFT JOIN, here green part is output for LEFT JOIN.

Here we will consider one example for LEFT JOIN condition where we will use
two tables named as SalesDetails and ClientDetails.
Table Name: SalesDetails
Table Name: ClientDetails

As you can see, first table has 8 records and second table has 10 records. From above
two tables, we need columns OrderID and OrderDate from SalesDetails table and one
column ClientName from ClientDetails table and sorted in ascending
order by OrderDate column. So to get the output from two tables we will use LEFT JOIN
query as given below.

SELECT SalesDetails.OrderID, ClientDetails.ClientName, SalesDetails.OrderDate


FROM SalesDetails LEFT JOIN ClientDetails
ON SalesDetails.ClientID = ClientDetails.ClientID
ORDER BY OrderDate

So, in LEFT JOIN all the records are returned from the table which is mentioned in left side.

Also Refer:
 SQL JOINS
 SQL INNER JOIN
 SQL RIGHT JOIN
 SQL FULL JOIN
 SQL CROSS JOIN

You might also like