How to do the following SQL query?

1

Hi, I'm starting to work with SQL, I'd appreciate it if you could help me because I have trouble making the next query, I do not know how to do it

TABLE employees 
id INTEGER NOT NULL PRIMARY KEY 
managerId INTEGER REFERENCES employees(id) 
name VARCHAR(30) NOT NULL

How can I make a query that selects the names of employees who are not managers?

    
asked by R.C. Ana 22.02.2018 в 17:38
source

1 answer

7

A simple NOT EXISTS should be enough:

SELECT *
FROM Employees AS e
WHERE NOT EXISTS(SELECT 1 FROM Employees
                 WHERE managerId = e.Id);
    
answered by 22.02.2018 / 17:43
source