I am trying to select distinct users that are listed for other companies but not on my company (1). Here is an example
x
Placement User Company
1 1 1
2 1 2
3 2 2
4 3 1
5 2 1
From this table, I would like to get row 4 since he is in other company (not 1) but listed on others. I do not want others because they are listed on both my company and others. Anyone can help?
Advertisement
Answer
You can use NOT IN
. For example:
select distinct user
from t
where user not in (
select user from t where company = 1
)