【发布时间】:2016-09-27 07:50:29
【问题描述】:
我遇到mysql数据库错误
错误号:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'option, GROUP_CONCAT(DISTINCT year_question_map.year) AS years, GROUP_CONCAT(DIS' 附近使用正确的语法 SELECT `questions`.*, `question_level`.*, `question_answer`.*, GROUP_CONCAT(DISTINCT question_option.question_option SEPARATOR '__') AS 选项, GROUP_CONCAT(DISTINCT year_question_map.year) AS 年, GROUP_CONCAT(DISTINCT Exams.exam_name) AS 考试 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
我正在使用 Codeigniter,这是我模型中的 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?? -
question_option.question_option 不是 question_option.OPTIONNAME
-
可能因为同一个表和同一个列名而出错..
-
我已经使用不同的名称进行了检查,但它给出了相同的错误
标签: php mysql database codeigniter join