I have three tables: T1 has id's from T2 (client) and T3 (supplier), it also acts a black list: T1's rows with client's and supplier's id.
- I want to get the supplier's id the client can buy from.
.
currently T1 has three rows:
T1_id | T2_id | T3_id
1 1 3
2 1 4
3 2 3
I tried:
select T3.id
from T1
left join T2 on T2.id = T1.T2_id
right join T3 on T3.id != T1.T3_id
where T2.id = 1
the output is:
1
2
3
1
2
4
It should be only 1 and 2. What am I missing? It works fine with T2.id = 2.