三表
一、三表连接的格式
1.三表内连接
格式:select * from 表1 inner join 表2 on 表1.关联字段1=表2.关联字段2=表3.关联字段3;
如:select * from student student inner join sc on student.stu_no=sc.stu_no inner join course on sc.c_no=course.c_no;
2.三表隐藏内连接
格式:select * from 表1,表2,表3 where 表1.关联字段1=表2.关联字段2 and 表2.关联字段2=表3.关联字段3
如:select * from student student,sc,course where student.stu_no=sc.stu_no and sc.c_no=course.c_no;
3.三表左连接
格式:select * from 表1 left join 表2 on 表1.关联字段1=表2.关联字段2 left join 表3 on 表2.关联字段2 =表3.关联字段3;
如:select * from student left join sc on student.stu_no=sc.stu_no left join course on sc.c_no =course.c_no;
4.三表右连接
格式:select * from 表1 right join 表2 on 表1.关联字段1=表2.关联字段2 right join 表3 on 表2.关联字段2=表3.关联字段3;
如:select * from student right join sc on student.stu_no=sc.stu_no right join course on sc.c_no =course.c_no;
5.三表连接
格式:select * from(select * from 表1 left join 表2 on 表1.关联字段1=表2.关联字段2)别名 inner join 表3 on 表2.关联字段2=表3.关联字段3;
如:select * from (select a.,sc_no,c_no,score from student inner join sc on student.stu_no=sc.stu_no)s inner join course on s.c_no=course.c_no ;
备注:当字段有相同的,我们就先显示一个表的字段,表名.,加上另一个表的字段,显示所有得字段
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1201376.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!