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 :

SQL - LEFT JOIN
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 :

SQL - LEFT JOIN

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 :

Sql_left_JOIN


Advertisements

Add Comment

📖 Read More