方法一:三表隐藏内连接
格式:select * from 表1 , 表2 ,表3 where 表1.关联的字段=表3.关联字段 and 表2.关联字段=表3.表3字段
案例:select * from student as a , course as b , sc as c where a.stu_no=c.stu_no and b.c_no=c.c_no
方法二:三表普通内连接
格式:select * from 表1 INNER JOIN 表3 on 表1.关联的字段=表3.关联字段 inner join 表2 on 表2.关联字段=表3.表3字段
案例:select * from student as a INNER JOIN sc as c on a.stu_no=c.stu_no inner join course as b on b.c_no=c.c_no
方法三:三表普通左连接
格式:select * from 表1 left JOIN 表3 on 表1.关联的字段=表3.关联字段 left join 表2 on 表2.关联字段=表3.表3字段
案例:select * from student as a left JOIN sc as c on a.stu_no=c.stu_no left join course as b on b.c_no=c.c_no
方法四:三表普通右连接
格式:select * from 表1 right JOIN 表3 on 表1.关联的字段=表3.关联字段 right join 表2 on 表2.关联字段=表3.表3字段
案例:select * from student as a right JOIN sc as c on a.stu_no=c.stu_no right join course as b on b.c_no=c.c_no
方法五:先合两表,在两表合并成一表与第三个表合并
案例:select s.stu_no ,s.stu_name from ( select a.stu_no ,stu_name,c_no from student a ,sc c where a.stu_no=c.stu_no )s ,course as b where s.c_no=b.c_no
|
|