我有兩個mysql表,課程和student_courses,我需要從課程表中獲取唯一的course_names。但是當我嘗試執行我的查詢時遇到錯誤。嘗試使用DISTINCT和LEFT JOIN獲得唯一值時出現MySQL錯誤
繼承人我查詢
SELECT
sc.c_id,
DISTINCT c.course_name
FROM
Courses AS c
LEFT JOIN Student_Courses AS sc ON c.c_id = sc.c_id
WHERE
sc.s_id = 4
這是錯誤我得到
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 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 'DISTINCT c.course_name
FROM 課程爲C LEFT在3號線