Right Join Example:
Customers Table
CUSTOMER_ID | CUSTOMER_NAME | USER_NAME |
1 | CUSTOMER_1 | SYSTEM |
2 | CUSTOMER_2 | ELLEN |
3 | CUSTOMER_3 | TOM |
4 | CUSTOMER_4 | STEVE |
5 | CUSTOMER_5 | |
6 | CUSTOMER_6 | |
Users Table
USER_NAME | DEPARTMENT_NAME |
SYSTEM | IT |
TOM | SALES |
STEVE | SALES |
ELLEN | SALES |
JOHN | IT |
SELECT c.customer_id, c.customer_name, c.user_name
FROM users u RIGHT JOIN customers c
ON c.user_name = u.user_name
ORDER BY c.customer_id ;
Result:
Customer_Id | Customer_Name | User_Name |
1 | CUSTOMER_1 | SYSTEM |
2 | CUSTOMER_2 | ELLEN |
3 | CUSTOMER_3 | TOM |
4 | CUSTOMER_4 | STEVE |
5 | CUSTOMER_5 | |
6 | CUSTOMER_6 | |