The RIGHT JOIN keyword returns all rows from the RIGHT table (table_name2), even if there are no matches in the LEFT table (table_name1).
The MySQL RIGHT JOIN clause consists of RIGHT JOIN keyword followed by the second table you want to join. Next element is the ON keyword followed by the join condition. In the join condition, you specify the columns to be used for matching row in the two tables. The syntax of MySQL is as follows:
SELECT t1.c1, t1.c2,…t2.c1,t2.c2 FROM t1 RIGHT JOIN t2 ON t1.c1 = t2.c1 …(join_condition) WHERE where_condition
Let’s take a look at two table customers and orders: If you want to know which customer has which order and each order’s status. You can use the MySQL RIGHT JOIN as follows:
SELECT c.customerNumber, customerName,orderNUmber, o.status FROM customers c RIGHT JOIN orders o ON c.customerNumber = o.customerNumber LIMIT 10;
RIGHT JOIN is opposite the LEFT JOIN
0 comments:
Post a Comment