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:
SQL Fiddle demo