MySQL#1054-'字段列表'中的未知列'notes.schedule_id'

时间:2019-10-10 03:29:48

标签: mysql

我有一个查询,并且所有表的名称正确。突然,我得到了这个错误。我不知道该怎么办。我什至在sections表中创建了别名,因为之前遇到了错误#1066 - Not unique table/alias: 'sections'。有人可以告诉我该怎么办?谢谢

SELECT sectionschedules.id, notes.schedule_id, 
sections.id as b, sectionstudents.section_id, users.id, sections.sy_id FROM sections
LEFT JOIN sectionschedules on sectionschedules.id = notes.schedule_id
LEFT JOIN sections b on sections.id = sectionschedules.section_id
LEFT JOIN sectionstudents on sectionstudents.section_id = sections.id
LEFT JOIN users on users.id = sectionstudents.student_id
WHERE users.id = 10 AND sections.sy_id = 1 AND notes.status = 1;

1 个答案:

答案 0 :(得分:2)

查询中没有表notes,这就是为什么您无法正确执行查询的原因。

您致电notes.schedule_id,notes.status = 1;

编辑过::D

SELECT sections.name, sections.description, ss.id,
sections.id as b, ss.section_id, users.id, sections.sy_id FROM sections
    LEFT JOIN sectionschedules ss on sections.id = ss.section_id
    LEFT JOIN sectionstudents on sectionstudents.section_id = sections.id
    LEFT JOIN users on users.id = sectionstudents.student_id
    LEFT JOIN notes on ss.id = notes.schedule_id

检查您的where子句。 并分析它。 谢谢。