It seems complicated (and probably it is). But i cant imagine how to solve this.
There are tables:
COMPANIES
id | name
1 | Google
2 | Samsung
3 | Microsoft
PARAGRAPHS
id | name
1 | Header
2 | Body
3 | Footer
TAGS
id | tag
1 | Internet
2 | Softwate
COMPANIES_VS_TAGS
id | company_id | tag_id
1 | 1 | 1
2 | 2 | 2
3 | 3 | 1
4 | 3 | 2
PARAGRAPHS_VS_TAGS
id | paragraph_id | tag_id
1 | 2 | 1
1 | 2 | 2
I need to select all companies, that belongs to [any_number] of tags that belongs to paragraph by logical AND.
So, in the example above, the Body paragraph should output the only company "Microsoft".
ADD: I can use only WHERE and SubQueries: this is the limitation of CMS i have to use.