错误1052(23000):where子句中的'course_id'列不明确

use*_*346 2 mysql

我是MySQL新手所以请告诉我,如果我的问题缺少信息,

我有一个工作正常的查询:

select au.email, sm.created, sm.grade, sm.max_grade
from auth_user au, courseware_studentmodule sm
where sm.student_id = au.id
and course_id = 'MyCourse'
and sm.module_type = 'problem';
Run Code Online (Sandbox Code Playgroud)

但是当我想从另一个表中添加另一个列时:

select au.email, sm.created, sce.created , sm.grade, sm.max_grade
from auth_user au, courseware_studentmodule sm,  student_courseenrollment sce
where sm.student_id = au.id and sm.student_id = sce.id
and course_id = 'MyCourse'
and sm.module_type = 'problem';
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

ERROR 1052 (23000): Column 'course_id' in where clause is ambiguous
Run Code Online (Sandbox Code Playgroud)

谁知道为什么?

谢谢

Lor*_*yer 6

这是因为列course_id存在于两个以上的表中.

写sm.course_id或sce.course_id,它会起作用.