MySQL: Right Join

Profile picture for user arilio666

The RIGHT JOIN in MySQL will work exactly as opposed to that of LEFT JOIN. Here, the entire record of the right table will be displayed irrespective while the left table content is displayed only about the matching ones.

So to put it simply right table content is displayed even though there is no match whereas it is not applicable for the left side table content.

Syntax

SELECT * from TableName1 RIGHT JOIN TableName2 ON TableName1.CommonColumn1 = TableName2.CommonColumn1

The TableName2 on the right will be displayed fully whereas the TableName1 queried on the left only displays its content with the match.

So let us dive into some real-time practical examples.

For this example, we will be working again with the products table as left and the products extra table as of right.

Today we will be matching the products based on the product_id from the products table with the products extra table.

Example

select * from products right join productsextra on products.product_id = productsextra.product_id;

So from here, we can see that the table which is joined on the right that is the products extra table is displayed fully without any skip whereas the left table has been displayed before its matching column only.

Tags