Mysqli Mysql-选择列“A”,即使为空

Mysqli Mysql-选择列“A”,即使为空,mysqli,Mysqli,表A包含学生姓名,表B和C包含班级和学生人数。 我想展示所有学生并出席他们的活动。问题是,我无法显示所有没有检查状态的学生。 在我检查学生是否在场的地方,这是可以的,但如果在给定的班级、给定的日期和给定的科目中没有检查过的在场,则不会显示任何内容 我的问题是: SELECT student.id_student, CONCAT(student.name,' ' ,student.surname) as 'name_surname',pres_student_present, pres_stude

表A包含学生姓名,表B和C包含班级和学生人数。 我想展示所有学生并出席他们的活动。问题是,我无法显示所有没有检查状态的学生。 在我检查学生是否在场的地方,这是可以的,但如果在给定的班级、给定的日期和给定的科目中没有检查过的在场,则不会显示任何内容

我的问题是:

SELECT student.id_student, CONCAT(student.name,' ' ,student.surname) as 'name_surname',pres_student_present, pres_student_absent, pres_student_justified, pres_student_late, pres_student_rel, pres_student_course, pres_student_delegation, pres_student_note FROM student
    LEFT JOIN class ON student.no_classes = class.no_classes
    LEFT JOIN pres_student ON student.id_student = pres_student.id_student
    WHERE (class.no_classes = '$class' OR NULL AND pres_student_data = '$data' AND pres_student_id_subject = $id_subject OR NULL)
    GROUP BY student.surname
    ORDER BY student.surname ASC
我希望始终显示name_姓氏,任何其他列都应为NULL或1 比如: 姓名|出席|缺席|刚刚|迟到|相关|授权|备注| 唐纳德·特朗普| 1 | | | | | || 灌木丛| 某人| 1 | | | | | ||
等等。

您应该将对class和pres_studenttables的限制从WHERE子句移动到左侧联接

在你的情况下,当你用一个外部连接在一个表中的WHERE子句中执行一个约束时,SQL引擎认为你正在执行一个内部联接< /P>


好吧,现在我明白了。伟大的我需要添加WHERE class.no_class='$class',它就可以工作了!如果没有它,SQL将显示特定类中的所有学生。谢谢。
SELECT    student.id_student
        , CONCAT(student.name, ' ', student.surname) AS 'name_surname'
        , pres_student_present
        , pres_student_absent
        , pres_student_justified
        , pres_student_late
        , pres_student_rel
        , pres_student_course
        , pres_student_delegation
        , pres_student_note
FROM      student
LEFT JOIN class
       ON student.no_classes = class.no_classes
      AND class.no_classes   = '$class'
LEFT JOIN pres_student
       ON student.id_student      = pres_student.id_student
      AND pres_student_data       = '$data'
      AND pres_student_id_subject = $id_subject
GROUP     BY student.surname
ORDER     BY student.surname ASC