I've asked this Question on https://stackoverflow.com/q/49202343/9113120 Before and got and Answer, But I would like to understand how to deal with this kind of relation: In this Query: http://sqlfiddle.com/#!9/fee4c6/3/0 SELECT d.`id`, COUNT(da.`doc_id`), COUNT(db.`doc_id`) FROM `docs` d LEFT JOIN `docs_scod_a` da ON da.`doc_id` = d.`id` LEFT JOIN `scod_a` a ON a.id = da.`doc_id` LEFT JOIN `docs_scod_b` db ON db.`doc_id` = d.`id` LEFT JOIN `scod_b` b ON b.`id` = db.`doc_id` GROUP BY d.`id`; `scod_a: a.id` depends on `docs_scod_a: da.doc_id` which depends on `docs: d.id` What I want to do is `SELECT` the `id`s from `Table: docs` with the `COUNT()` of their related `doc_id`s from `Table: docs_scod_a, docs_scod_b`, Which is supposed to give me: | id | COUNT(da.`doc_id`) | COUNT(db.`doc_id`) | |----|--------------------|--------------------| | 1 | 3 | 3 | | 2 | 3 | 1 | | 3 | 2 | 3 | | 4 | 0 | 1 | Then I filter the values using the `IN() clause` with `Table: scod_a, scod_b` columns of `ver_a, ver_b` by order using `WHERE a.ver_a IN ('AA') AND b.ver_b IN ('BA')`: http://sqlfiddle.com/#!9/fee4c6/21/0 What I expect the results having the `AA` and `BA` to return only the `ROW`s having `AA` from `Table: scod_a` and `BA` from `Table: scod_b` so the result would be: | id | COUNT(da.`doc_id`) | COUNT(db.`doc_id`) | |----|--------------------|--------------------| | 1 | 3 | 3 | But as I mentioned in the previous Question, I get without `IN clause` the values: | id | COUNT(da.`doc_id`) | COUNT(db.`doc_id`) | |----|--------------------|--------------------| | 1 | 9 | 9 | | 2 | 3 | 3 | | 3 | 6 | 6 | | 4 | 0 | 1 | And with `IN clause` the values: | id | COUNT(da.`doc_id`) | COUNT(db.`doc_id`) | |----|--------------------|--------------------| | 1 | 9 | 9 | ---------- I want to understand What is the proper way to deal with these types of Queries with the shown example, Not just to solve the Problem. ---------- It is more about how do I use `IN() clause` within 3-Tables Relation, But with 6-Tables, 3 for Each type like here for `scod_a` and `docs_scod_a` only http://sqlfiddle.com/#!9/f9a33f/5/0 But I want to add the `scod_b` and `docs_scod_b` too into the query as in the main query http://sqlfiddle.com/#!9/fee4c6/21/0 Which didn't work and gave false values