SQL – LEFT JOIN
SQL -LEFT JOIN
SQL – LEFT JOIN `selects all rows from left table and the matching rows from the right table.
Syntax : SQL – LEFT JOIN
SELECT LeftTable.ColumnName1,LeftTable.ColumnName2…RightTable.ColumnName1,RightTable.ColumnName2… FROM LeftTable LEFT JOIN RightTable ON (LeftTable.ColumnName = RightTable.ColumnName);
We Have The Following Tables :
Orders Table :
Note : “UserId” In “Orders” Table is the id of the users which is assigned to users in “Users” Table in “ID” column. The Values stored in “UserId” Column are reffered from “Users” Table.
And
Users Table :
Left Join Example Can Be Explained Using The Above Two Tables :
Example
SELECT Users.Name,Users.Email,Orders.OrderItem FROM Users LEFT JOIN Orders ON (Users.ID= Orders.UserId);
The Above Left Join Will Produce :
Advertisements