场景
在查询学生信息中,允许学生宿舍信息为空,如果有获取,没有为空
select t.*, cs_sc_studenthostel.name as hostelname
from (
select cs_sc_student.id as student_id,
cs_sc_student.name as studentname,
cs_sc_class.name as classname,
cs_sc_student.sc_studenthostel_id
from cs_sc_student, cs_sc_class
where cs_sc_student.sc_class_id = cs_sc_class.id) t
left join cs_sc_studenthostel on t.sc_studenthostel_id = cs_sc_studenthostel.id
第一步 获取到学生的基础信息
(
select cs_sc_student.id as student_id,
cs_sc_student.name as studentname,
cs_sc_class.name as classname,
cs_sc_student.sc_studenthostel_id
from cs_sc_student, cs_sc_class
where cs_sc_student.sc_class_id = cs_sc_class.id) t
第二步 进行左连接
left join cs_sc_studenthostel on t.sc_studenthostel_id = cs_sc_studenthostel.id
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。