I'm trying to hang NOT EXISTS and I'm having problems. Let's say I have 2 tables.
Employees: +------+------+ | eid | name | +------+------+ | 1 | Bob | | 2 | Alice| | 3 | Jill | +------+------+ Transactions: +----------+----------+----------+-----------+ | tid | eid | type | amount | +----------+----------+----------+-----------+ | 1 | 1 | Deposit | 50 | | 2 | 1 | Open | 500 | | 3 | 3 | Open | 200 | | 4 | 2 | Withdraw | 25 | | 5 | 2 | Open | 100 | +----------+----------+----------+-----------+
Let's say I want to find the names of all the employees who did not open any account in the amount of $ 250 or higher. This means that I only need the lines in which the employee opened an account with an amount of <$ 250. Right now I have something like this ...
SELECT name FROM Employees e WHERE NOT EXISTS ( SELECT * FROM Transactions t WHERE t.type <> 'Open' AND t.amount >= 250 AND t.eid = e.eid);
This is obviously wrong, and I really don't understand why.
source share