zhaoyqiu的数据分析进阶之路2.0

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'


解决办法:
需要把联合的表用括号括起来,并且括起来之后不能取别名:
正确写法 :

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;

注意:括起来之后也不要起别名,不然也会报错


上一篇 下一篇

猜你喜欢

热点阅读