有3张表,学生、科目、和成绩表。
student{id,name,age,sex,grade},
result{id,subject_id,student_id}
subject{id,subject_name}.
当使用where条件过滤时,会过滤掉找到记录中满足条件的记录,而对于左连接也是适用的。 如下图:
****对于where过滤条件,此针对的是查询出来的总的记录,而不会因是left join而不过滤*****
select s.id,s.name,s.age,s.sex,s.grade,
r.subject_id,r.student_id,
su.subject_name,su.id
from student s
left join result r on s.id=r.student_id
left join subject su on r.subject_id=su.id
where su.subject_name='数学'