使用DESC命令对连接进行mysql查询

时间:2014-02-01 09:30:38

标签: mysql

SELECT a.id, b.title, b.identifier,c.rating 
FROM mdl_course_modules a 
    LEFT JOIN mdl_scorm_scoes b 
        ON a.instance = b.scorm 
    and b.scormtype = ''
    LEFT JOIN training_rating C 
    ON C.training_id = a.id  
    and c.user_id = '1'
WHERE a.module='18'
ORDER BY rating DESC

error in : #1054 - Unknown column 'c.rating' in 'field list'

1 个答案:

答案 0 :(得分:1)

您将traning_rating别名为C,但您将其称为c(小写),这是错误的原因。请试试这个:

SELECT a.id, b.title, b.identifier,c.rating 
FROM mdl_course_modules a 
    LEFT JOIN mdl_scorm_scoes b 
    ON a.instance = b.scorm and b.scormtype = ''
    LEFT JOIN training_rating c
    ON c.training_id = a.id and c.user_id = '1'
WHERE a.module='18'
ORDER BY rating DESC