I have the following query:
select distinct a.id, a.name
from Employee a
join Dependencies b on a.id = b.eid
where not exists
(
select *
from Dependencies d
where b.id = d.id
and d.name = 'Apple'
)
and exists
(
select *
from Dependencies c
where b.id = c.id
and c.name = 'Orange'
);
I have two tables, relatively simple. The first employee has an identifier column and a column of names. The second table of Dependencies has 3 columns, id, eid (employee identifier for the link) and names (apple, orange, etc.).
the data is as follows: The employee table is as follows:
id | name
-----------
1 | Pat
2 | Tom
3 | Rob
4 | Sam
Dependencies
id | eid | Name
--------------------
1 | 1 | Orange
2 | 1 | Apple
3 | 2 | Strawberry
4 | 2 | Apple
5 | 3 | Orange
6 | 3 | Banana
As you can see, Pat has both Orange and Apple, and it needs to be excluded, and it must be through connections, and I cannot get it to work. Ultimately, only Rob should return data
source
share