T-SQL Tutorial

SQL Right Join


Right Join Example:

SELECT * FROM employee e RIGHT JOIN department d
ON e.DEP_ID = d.DEP_ID
ORDER BY d.DEP_ID ;

Employee table:

EMPLOYEE_IDNAMEDEP_ID
1EMPLOYEE_121
2EMPLOYEE_222
3EMPLOYEE_323
4EMPLOYEE_424
5EMPLOYEE_5

Department table:

DEP_IDDEP_NAME
21DEP_21
22DEP_22
23DEP_23
24DEP_24
25DEP_25

Right Join Result:

EMPLOYEE_IDNAMEDEP_IDDEP_IDDEP_NAME
1EMPLOYEE_12121DEP_21
2EMPLOYEE_22222DEP_22
3EMPLOYEE_32323DEP_23
4EMPLOYEE_42424DEP_24
25DEP_25