I'm trying to get article content_item_id
-s from Joomla contentitem_tag_map
table, where tag_id
equals to one or more values. The problem is that in Joomla (3.5), all tag associations are displayed in different rows, like that:
Query involved columns from contentitem_tag_map
table:
| content_item_id | tag_id | -------------------------------- | 4 | 7 | -------------------------------- | 8 | 6 | -------------------------------- | 9 | 5 | -------------------------------- | 9 | 9 | -------------------------------- | 11 | 3 | -------------------------------- | 11 | 9 | -------------------------------- | 12 | 3 | --------------------------------
My question is, with what query can I get content_item_id
-s from this table, if it must have two or more tag_id
-s?
For example:
I want to get all content_item_id
-s that have tag_id
"3" AND "9" (result should be "11")
OR
I want to get all content_item_id
-s that have tag_id
"5" AND "9" (result should be "9")
My current query is as follows:
$articleIDQuery = $db->getQuery(true); $articleIDQuery->select('distinct content_item_id'); $articleIDQuery->from($db->quoteName('#__contentitem_tag_map')); $articleIDQuery->where($db->quoteName('tag_id')." IN (3,9)"); $db->setQuery($articleIDQuery); $taggedArticleID = $db->loadObjectList();
This query results in displaying content_item_id
-s that have tag_id
-s "3" OR "9" instead of "3" AND "9"
I would really appreciate if anyone can give me any ideas on how to get the wanted results. I'm pretty much a SQL newbie, so google'ing the answers is way too complicated, since I can't really put my idea into one sentence.
Thank you in advance.