• Yes, employee 45 SHOULD show up in this list, because nobody reports to them.

    Add another record where someone reports to 45, then 45 will not appear - even if you delete its parent record:

    create table #employees (employeeid int, reportsto int)

    insert #employees select 10, null

    insert #employees select 45, 10

    insert #employees select 50, 45

    --here is the original query - we find employee 50 as the only one who does not have anyone reporting to them

    select *

    from #employees

    left join #employees as subordinates on #employees.employeeid = subordinates.reportsto

    where subordinates.employeeid Is Null

    --now delete the reportsto record

    delete #employees where employeeid = 10

    -- we still get the same answer, 45 still does not appear, even though its parent is deleted

    select *

    from #employees

    left join #employees as subordinates on #employees.employeeid = subordinates.reportsto

    where subordinates.employeeid Is Null

    drop table #employees