If I have a table like that :
ID MANAGER_ID NAME
1 2 Ahmed
2 3 Mostafa
3 NULL Mohamed
4 1 Abbas
5 3 Abdallah
If I wanted a sql statement to get the name of the managers in this company! how it will be?
The question is a little trickier than it seems at first glance:
select Name
from t
where id in (select manager_id from t)
The query seems to require some sort of self-join, because the information about who is a manager is in the manager_id column. This does the self-join using in in the where clause
You just need
SELECT NAME from table_name
I just realized that you want it only where the Manager is NULL,
SELECT NAME from table_name WHERE MANAGER_ID IS NOT NULL
As I have been pointed out this will exude manager 3 because he is a manager as he manages other users. See @Gordon's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With