我有3個表格:項目,技能和project_skills。在項目表中,我持有項目的一般數據。第二個表技能我擁有技能ID和技能名稱我也有project_skills表是持有項目的技能關係。下面是表的方案:如何創建這個複雜的查詢?
CREATE TABLE IF NOT EXISTS `project_skills` (
`project_id` int(11) NOT NULL,
`skill_id` int(11) NOT NULL,
KEY `project_id` (`project_id`),
KEY `skill_id` (`skill_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;
CREATE TABLE IF NOT EXISTS `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`employer_id` int(11) NOT NULL,
`project_title` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`project_description` text COLLATE utf8_turkish_ci NOT NULL,
`project_budget` int(11) NOT NULL,
`project_allowedtime` int(11) NOT NULL,
`project_deadline` datetime NOT NULL,
`total_bids` int(11) NOT NULL,
`average_bid` int(11) NOT NULL,
`created` datetime NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `created` (`created`),
KEY `employer_id` (`employer_id`),
KEY `active` (`active`),
FULLTEXT KEY `project_title` (`project_title`,`project_description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `skills` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` int(11) NOT NULL,
`name` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`seo_name` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`total_projects` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `seo_name` (`seo_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=224 ;
我要選擇具有相關技能的名字項目。我想我必須使用JOIN,但我不知道該怎麼辦。由於
這是值得一讀一個SQL教程作爲複習。 http://www.w3schools.com/sql/sql_join.asp – 2010-06-05 14:45:56
請舉例說明「相關技能名稱」。 – 2010-06-05 20:47:30
技能ID - 項目ID關係在項目技能名稱中保留,但我想要在技能表中保存的技能名稱。我的意思是這些技能名稱通過說「相關技能名稱」 – mTuran 2010-06-06 22:46:03