杭州10期_单奇 发表于 2021-8-15 19:11:54

数据库查询_三表查询

三表连接
方法一:三表隐藏内连接
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 and c_name = "计算机原理"
方法二:三表普通内连接
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 student as a LEFT JOIN sc as c on a.stu_no=c.stu_noLEFTJOIN course as b on b.c_no=c.c_no

方法四:三表普通右连接
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
方法五:先合两表,在两表合并成一表与第三表合并
selects.stu_no ,s.stu_name from ( selecta.stu_no ,stu_name,c_nofrom student a,sc c wherea.stu_no=c.stu_no )s, courseas bwheres.c_no=b.c_no

页: [1]
查看完整版本: 数据库查询_三表查询