ERROR 1054 (42S22): Unknown colu
2020-07-18 本文已影响0人
喝奶茶不加奶茶
环境:
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'
![](https://img.haomeiwen.com/i21398523/4607ef1c9783b920.png)
解决办法:
需要把联合的表用括号括起来,并且括起来之后不能取别名:
正确写法 :
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;
![](https://img.haomeiwen.com/i21398523/77f3703dfbd155cc.png)
注意:括起来之后也不要起别名,不然也会报错
![](https://img.haomeiwen.com/i21398523/16058c8882a3b52e.png)