首页 > 数据库技术 > 详细

mysql left join 运用

时间:2017-10-18 18:05:05      阅读:249      评论:0      收藏:0      [点我收藏+]

select student_id,student.sname FROM score LEFT JOIN student on student_id=student.sid where course_id in(
select cid from course LEFT JOIN teacher on course.teacher_id=teacher.tid where teacher.tname=‘李平老师‘
) GROUP BY student_id -- LEFT JOIN必须在from 表名的后面 若放在 where 后面 或group 后面 将报错,如下:

select student_id,student.sname FROM score where course_id in(
select cid from course LEFT JOIN teacher on course.teacher_id=teacher.tid where teacher.tname=‘李平老师‘
) LEFT JOIN student on student_id=student.sid  GROUP BY student_id --error

select student_id,student.sname FROM score where course_id in(
select cid from course LEFT JOIN teacher on course.teacher_id=teacher.tid where teacher.tname=‘李平老师‘
)GROUP BY student_id LEFT JOIN student on student_id=student.sid   --error

mysql left join 运用

原文:http://www.cnblogs.com/whigo/p/7687988.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!