I need some hints.. I got a tables which look like that:
| ID | ITEM |
|---|---|
| 1 | XXXX |
| 2 | YYYY |
| 3 | ZZZZ |
| ID | ID_2 | SUBITEM |
|---|---|---|
| 1 | 10 | AA |
| 1 | 11 | BB |
| 2 | 12 | CC |
| 2 | 13 | DD |
| 3 | 14 | EE |
| 3 | 15 | FF |
| 3 | 16 | GG |
| ID_2 | value |
|---|---|
| 10 | 1 |
| 11 | 0 |
| 12 | 1 |
| 13 | 1 |
| 14 | 1 |
| 15 | 1 |
| 16 | 0 |
I need to get all items where ALL sub-items are = 1.
for example XXXX should not be listed, because BB has value 0.
select distinct
(table1.item)
from table1,
table2,
table3
where table1.id = table2.id
and table2.id_2 = table3.id_2
and table3.value = 1
order by table1.item
my code gives me all items wherever 1 is a value
Thanks for help!