I want to obtain all rows that contain processed = 1 and approved = 1 for the different ids but if the same id has any row with processed = 0 and approved = 0 then, i dont want to obtain anything for that specific id.
This is what i want:
Here is my query:
select * from table1 oa
inner join table2 kio on oa.id = kio.id_table_1
inner join table3 joi on kio.col3 = joi.col3_id_table_2
where joi.processed = 1
and joi.approved = 1
SQL FIDDLE:
http://sqlfiddle.com/#!9/fc7266/3
I think the best way to solve this is using group by and having condition but it is not working for me
EDIT:
Another guy wanted to do this: "get all rows that just contain cols3 = 1 and cols3 =2 ONLY , (just values 1 and 2) and the output will be : "A" for the table given, i dont want to have C because it has another values of cols 3 != of 1 or 2"
Col 1 Col 2 Col 3
1 A 1
2 A 2
3 B 1
4 C 1
5 C 2
6 D 1
7 C 3
and he solved his problem by using this query:
select col2
from yourtable
group by col2
having sum(col3=1) > 0
and sum(col3=2) > 0
and sum(col3 not in (1,2)) = 0
Is it possible to do that in my case?