I looked at an article about CROSS APPLYand OUTER APPLYin SQL Server. The following tables were used to illustrate both.
Employees table:
EmployeeID FirstName LastName DepartmentID
1 Orlando Gee 1
2 Keith Harris 2
3 Donna Carreras 3
4 Janet Gates 3
Department table:
DepartmentID Name
1 Engineering
2 Administration
3 Sales
4 Marketing
5 Finance
I realized that it OUTER APPLYlooks like LEFT OUTER JOIN.But when I applied OUTER APPLYbetween the tables as shown below,
select * from Department e
outer apply
Employee d
where d.DepartmentID = e.DepartmentID
I got the results below (Same as the results INNER JOIN)
DepartmentID Name EmployeeID FirstName LastName DepartmentID
1 Engineering 1 Orlando Gee 1
2 Administration 2 Keith Harris 2
3 Sales 3 Donna Carreras 3
3 Sales 4 Janet Gates 3
When I applied OUTER APPLYbetween tables as shown below (with right tableas a subquery).
select * from Department e
outer apply
(
select * from
Employee d
where d.DepartmentID = e.DepartmentID
)a
I got below results (Same as results LEFT OUTER JOIN)
DepartmentID Name EmployeeID FirstName LastName DepartmentID
1 Engineering 1 Orlando Gee 1
2 Administration 2 Keith Harris 2
3 Sales 3 Donna Carreras 3
3 Sales 4 Janet Gates 3
4 Marketing NULL NULL NULL NULL
5 Finance NULL NULL NULL NULL
Can someone explain why the two requests gave different outputs?