Tag Archives: mysql right join multiple tables example
SQL – RIGHT JOIN
SQL – RIGHT JOIN
SQL – LEFT JOIN `selects all rows from right table and the matching rows from the left table.
SQL – RIGHT JOIN Syntax
:
SELECT LeftTable.ColumnName1,LeftTable.ColumnName2…RightTable.ColumnName1,RightTable.ColumnName2… FROM LeftTable RIGHT 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 RIGHT JOIN Orders ON (Users.ID= Orders.UserId);
The Above Left Join Will Produce :