SQL RIGHT JOIN
- RIGHT JOIN performs a join starting with the second (right-most) table and then any matching first (left-most) table records.
- RIGHT JOIN and RIGHT OUTER JOIN are the same.
The SQL RIGHT JOIN syntax
The general syntax is:- SELECT column-names FROM table-name1 RIGHT JOIN table-name2 ON column-name1 = column-name2 WHERE condition
The general RIGHT OUTER JOIN syntax is:
- SELECT column-names FROM table-name1 RIGHT OUTER JOIN table-name2 ON column-name1 = column-name2 WHERE condition
SQL RIGHT JOIN Example
1) Example of Right outer join
mysql> select customers.customername, orders.orderid from customers right join orders on customers.customerid = orders.customerid;
+---------------+---------+
| customername | orderid |
+---------------+---------+
| Mike Wooksahi | 10308 |
| NULL | 10309 |
| NULL | 10310 |
+---------------+---------+
3 rows in set (0.00 sec)
2) Example of Right outer join with order by Clause
+---------------+---------+
| customername | orderid |
+---------------+---------+
| Mike Wooksahi | 10308 |
| NULL | 10309 |
| NULL | 10310 |
+---------------+---------+
3 rows in set (0.00 sec)
2) Example of Right outer join with order by Clause
mysql> select customers.customername, orders.orderid from customers right join orders on customers.customerid = orders.customerid order by customers.customername;
+---------------+---------+
| customername | orderid |
+---------------+---------+
| NULL | 10310 |
| NULL | 10309 |
| Mike Wooksahi | 10308 |
+---------------+---------+
3 rows in set (0.00 sec)
Comments
Post a Comment