码迷,mamicode.com
首页 > 数据库 > 详细

mysql left join 运用

时间:2017-10-18 18:29:34      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:each   表名   mysql   sel   group by   teacher   报错   left join   error   

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 运用

标签:each   表名   mysql   sel   group by   teacher   报错   left join   error   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!