select employee, managerid
from your_table
where managerid is null
or managerid = id
Display all managers and employees without a manager
-
24-06-2022 - |
Вопрос
I have a table in SQL Server 2008 that for explanation purposes contains, ID, Employee and ManagerID.
eg:
ID Employee ManagerID
1 A NULL
2 B 2
3 C 2
I want to write a query that returns all non related ManagerID
's and ID
's where ManagerID
is equal to the ID
.
The result should look like this,
ID Employee ManagerID
1 A NULL
2 B 2
In essence no managers can be managers of managers.
At first I thought that it would be simple using a SELF Join and an EXCLUDE
SQL statement however I cannot get this to work. I would prefer not to USE the EXCLUDE
statement as my actual table has more columns and related data that I would like to return.
If you could help, I would be grateful.
Решение
Не связан с StackOverflow