i have table T1
ID
1
2
3
and table T2
ID HISTORY
1 1
1 1
2 1
2 0
I must select from T1 all records which does not exist in T2 or exists but all records are in history (history flag =1)
So for this my result will be
1
3
What is the correct SQL query for this? Thanks
try this:
select * from T1
where ID not in(select ID from T2 where HISTORY_FLG!=1)
Try to use not exists
select *
from t1 t
where not exists
(
select 1
from t2 a
where a.id = t.id
and a.HISTORY <> 1
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With