sql - Display all managers and employees without a manager -
i have table in sql server 2008 explanation purposes contains, id, employee , managerid.
eg:
id employee managerid 1 null 2 b 2 3 c 2
i want write query returns non related managerid
's , id
's managerid
equal id
.
the result should this,
id employee managerid 1 null 2 b 2
in essence no managers can managers of managers.
at first thought simple using self join , exclude
sql statement cannot work. prefer not use exclude
statement actual table has more columns , related data return.
if help, grateful.
select employee, managerid your_table managerid null or managerid = id
Comments
Post a Comment