ERROR 1054 (42S22): Unknown colu

作者: 喝奶茶不加奶茶 | 来源:发表于2020-07-18 19:38 被阅读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;
    

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


    相关文章

      网友评论

        本文标题:ERROR 1054 (42S22): Unknown colu

        本文链接:https://www.haomeiwen.com/subject/kuvfkktx.html