Hi,I have a question with regards to a SELECT query. I have the following tables:- task with task_details- tag table with tags- task_has_tag specifies which task has which tagMy aim is now to get all tasks which have specfic tags. I tried the following, but I now get all tasks which have one of the tags, I would like to create an SQL where all tasks are returned which have all tags (AND relatioN).Here's the query to get all tasks which have one of the tags. I thought that it should be somehow possible to get only those records where the number of results within this table is equal to the number of tags I'm searching for. Please note that the sql is created genericaly and that the number of tags is not fix.SELECT t . *FROM STATUS AS s, task AS tLEFT JOIN task_has_tag AS tht ON tht.task_id = t.task_idLEFT JOIN tag AS tg ON tht.tag_id = tg.tag_idWHERE (tg.tag_name = 'projectA'OR tg.tag_name = 'project')AND t.task_status = s.status_idAND (SELECT COUNT( * )FROM STATUS AS s2WHERE s2.parent_status = s.status_id) >0ORDER BY IF( ISNULL( task_latest_due_date ) , 1, 0 ) , task_latest_due_date
Here are the create statements of the tables:---- Table structure for table `tag`--CREATE TABLE IF NOT EXISTS `tag` ( `tag_id` int(11) NOT NULL auto_increment, `tag_name` varchar(50) NOT NULL, PRIMARY KEY (`tag_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;-- ------------------------------------------------------------ Table structure for table `task`--CREATE TABLE IF NOT EXISTS `task` ( `task_id` int(11) NOT NULL auto_increment, `task_subject` varchar(50) NOT NULL, `task_description` text, `task_planned_due_date` date default NULL, `task_latest_due_date` date default NULL, `task_status` int(11) NOT NULL, PRIMARY KEY (`task_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;-- ------------------------------------------------------------ Table structure for table `task_has_tag`--CREATE TABLE IF NOT EXISTS `task_has_tag` ( `task_id` int(11) NOT NULL, `tag_id` int(11) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Any help/idea is appreciated.Thanks