-2
我得到下面的mysql數據庫錯誤錯誤號:1064您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法
Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, GROUP_CONCAT(DISTINCT year_question_map.year) AS years, GROUP_CONCAT(DIS' at line 1 SELECT `questions`.*, `question_level`.*, `question_answer`.*, GROUP_CONCAT(DISTINCT question_option.question_option SEPARATOR '__') AS option, GROUP_CONCAT(DISTINCT year_question_map.year) AS years, GROUP_CONCAT(DISTINCT exams.exam_name) AS exams FROM `questions` LEFT JOIN `question_option` ON `question_option`.`question_id` = `questions`.`qid` LEFT JOIN `question_level` ON `question_level`.`level_id` = `questions`.`level_id` LEFT JOIN `question_answer` ON `question_answer`.`question_id` = `questions`.`qid` LEFT JOIN `year_question_map` ON `year_question_map`.`question_id` = `questions`.`qid` LEFT JOIN `exams` ON `exams`.`exam_id` = `year_question_map`.`exam_id` WHERE `questions`.`topic_id` = '1' GROUP BY `questions`.`qid` ORDER BY `qid` ASC
我使用笨,這裏的手冊是我的SQL查詢在我的模型
$this->db->select("questions.*,question_level.*,question_answer.*,GROUP_CONCAT(DISTINCT question_option.question_option SEPARATOR '__') AS option,GROUP_CONCAT(DISTINCT year_question_map.year) AS years,GROUP_CONCAT(DISTINCT exams.exam_name) AS exams");
$this->db->from('questions');
$this->db->join('question_option','question_option.question_id = questions.qid','left');
$this->db->join('question_level','question_level.level_id = questions.level_id','left');
$this->db->join('question_answer','question_answer.question_id = questions.qid','left');
$this->db->join('year_question_map','year_question_map.question_id = questions.qid','left');
$this->db->join('exams','exams.exam_id = year_question_map.exam_id','left');
$this->db->where('questions.topic_id',$topicID);
$this->db->group_by('questions.qid');
$this->db->order_by('qid','ASC');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return FALSE;
}
'question_option.question_option' ??或'question_option.OPTIONNAME'? – devpro
question_option.question_option NOT question_option.OPTIONNAME – imZiaur
可能因爲同一個表格和相同的列名稱而出現錯誤。 – devpro