** SOLVED **
I have two tables: jos_k2_items AND jos_k2_tags_xref
The items table contains articles that belong in my CMS (content management system). The tags_xref table maps the tags to the articles.
I am trying to search for articles based on having multiple tags assigned to them. In the example SQL below, I want articles that are tagged with tags, 3, 1, and 2. The way it is written now, it will show articles tagged with tags, 3, 1, or 2.
Thank you in advance. If I am missing anything please do not hesitate to ask.
Code:
SELECT DISTINCT(i.id)
FROM `jos_k2_items` i
INNER JOIN `jos_k2_tags_xref` tx
ON i.id=tx.itemID
WHERE tx.tagID IN (3,1,2)
CREATE TABLE `jos_k2_tags_xref` (
`id` int(11) NOT NULL auto_increment,
`tagID` int(11) NOT NULL,
`itemID` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `tagID` (`tagID`,`itemID`)
) ENGINE=MyISAM;
CREATE TABLE `jos_k2_items` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`catid` int(11) NOT NULL,
`published` smallint(6) NOT NULL default '0',
`introtext` text NOT NULL,
`fulltext` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
** jos_k2_items table trimmed down to keep this cleaner.