学生表(stu)
课程表(sub)
分数表(scores)
查出这三个表的信息,当学生缺考的时候,scores表中是没有记录存在的,但是查询的结果要求缺考的同学的信息也要现实出来。
SELECT stu.`name`,sub.`name`,scores.`score` FROM
(scores RIGHT JOIN stu ON scores.stu_id=stu.id)
LEFT JOIN sub ON sub.`id`=scores.`sub_id`;
查询结果