环境:
mysql 版本5
错误:
select * from students as stu ,subjects as sub
left join examinations as ex
on stu.student_id=ex.student_id
and sub.subject_name=ex.subject_name;
ERROR 1054 (42S22): Unknown column 'stu.student_id' in 'on clause'
解决办法:
需要把联合的表用括号括起来,并且括起来之后不能取别名:
正确写法 :
select * from (students as stu ,subjects as sub )
left join examinations as ex
on stu.student_id=ex.student_id
and sub.subject_name=ex.subject_name;
注意:括起来之后也不要起别名,不然也会报错
网友评论