Hello,
I have a table - Users: | id | name | manager_id |
The manager_id references the User.id,
I need to find an employee by an id or name and this employee has to be a manager to someone else.
The simplest initial idea was the following - do a sub-select and check if the id is present within the manager_id column, but this takes a bit of time.
Code:
SELECT usr.*
FROM Users usr
WHERE (
SELECT count(*)
FROM Users mg
WHERE mg.manager_id = usr.id AND
rownum = 1
) > 0) AND usr.name = 'John'
Is there a way to, for example, inner join the table to it self leaving only the rows that are managers?