I’m trying to solve this problem for past few days any help would be appreciated.
I have a Return item which have term1 in taxonomy1 AND term2 in taksonomy2.
This is my query:
SELECT items.*
FROM (`items`)
LEFT JOIN `rel_taxonomy` ON `rel_taxonomy`.`item_id` = `items`.`id`
LEFT JOIN `terms_taxonomy` ON `terms_taxonomy`.`terms_taxonomy_id` = `rel_taxonomy`.`terms_taxonomy_id`
LEFT JOIN `terms` ON `term`.`id` = `terms_taxonomy`.`term_id`
WHERE (items.org = '2') AND ( ((terms_taxonomy.taxonomy = '1') AND (term.pojam LIKE '%term1%')) AND ((terms_taxonomy.taxonomy = '2') AND (term.pojam LIKE '%term2%')))
GROUP BY `items`.`id`
If I replace the line:
WHERE (items.org = '2') AND ( ((terms_taxonomy.taxonomy = '1') AND (term.pojam LIKE '%term1%')) AND ((terms_taxonomy.taxonomy = '2') AND (term.pojam LIKE '%term2%')))
with the following (replacing an AND with an OR):
WHERE (items.org = '2') AND ( ((terms_taxonomy.taxonomy = '1') AND (term.pojam LIKE '%term1%')) OR((terms_taxonomy.taxonomy = '2') AND (term.pojam LIKE '%term2%')))
everything works fine. But I still need AND.
Table scheme
items
id | title | org
rel_taxonomy
item_id | terms_taxonomy_id
terms_taxonomy
terms_taxonomy_id | terms_id | taxsonomy
terms
id | term
so I’m trying to get item which have term1 in taxonomy1 AND term2 in taksonomy2.
Use
ORand add aHAVINGclause