2012-07-22 31 views
0

在此查詢中,DISTINCT關鍵字不起作用。從主題表顯示重複的主題..有誰可以告訴我我犯了什麼錯誤嗎?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

閱讀這個答案http://stackoverflow.com/questions/8203969/unexpected-sql-query-behavior-distinct/8203983#8203983 – 2012-07-22 10:33:40

+0

您的查詢有語法錯誤。請糾正它們。 – 2012-07-22 10:36:18

+0

我更新了我的查詢 – ugnuku 2012-07-22 10:39:58

回答

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