'Compare column values from different tables based on condition
I have two tables
table1
column1 column2
code1 abc
code1 xyz
code1 pqr
code2 abc
code2 xyz
code2 fgh
table2
column1 coulmn2
abc false
xyz false
pqr false
fgh true
now I want to retrieve the data of different code values from table1 which has value as false,
I tried joining two tables but I'm not getting desired result
select distinct t.coumn1
from table1 t join table2 t2 on t.coulmn2 = t2.cloumn1
where t2.culmn2 = false;
but I'm getting both code1 and code2 as result, need help in find out the right query
Solution 1:[1]
One way is using not exists
select distinct t.column1
from table1 t
where not exists (
select 1
from table1 t1
join table2 t2
on t1.column1 = t.column1 and t2.column1 = t1.column2 and t2.column2 <> 'false');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
