id | title
A_id | С_id
id | code
id | title
1 | title 1
2 | title 2
3 | title 3
A_id | С_id
1 | 1
1 | 2
2 | 3
3 | 4
id | code
1 | 0
2 | 1
3 | 0
4 | 1
SELECT * FROM A
INNER JOIN B
ON A.id = B.A_id
INNER JOIN C
ON B.B_id = C.id
GROUP BY A.id
HAVING C.code = 1