DISTINCT关键字在我的查询中不起作用

时间:2012-07-22 10:32:35

标签: php mysql sql

在此查询中,DISTINCT关键字无效。从主题表中显示重复的主题..任何人都可以告诉我哪里出错了吗?

SELECT DISTINCT
  tutor_category_subject.subject_id,
  GROUP_CONCAT(subject.subjects SEPARATOR ', ') AS subjects  
FROM       tutor_category_subject
INNER JOIN subject ON tutor_category_subject.subject_id = subject.subject_id
WHERE tutor_category_subject.tutor_id = 3;

1 个答案:

答案 0 :(得分:1)

我认为你需要一个分组声明:

SELECT tutor_category_subject.subject_id,
       GROUP_CONCAT(subject.subjects SEPARATOR ', ') AS subjects  
FROM tutor_category_subject INNER JOIN
     subject
     ON tutor_category_subject.subject_id = subject.subject_id
WHERE tutor_category_subject.tutor_id = 3
group by tutor_category_subject.subject_id