SQL——多表查询

相关知识:

join操作符

1.笛卡尔积,RXS

可直接转换为SQL语句

2.等值连接,记作

可直接转换为SQL语句

3.自然连接,记作

可转换为SQL语句

4.左外连接和右外连接的表示方法及转换为SQL

注意若多个关系有同名属性,则用 关系名.属性名 指出重名属性

连接也可以与投影,选择等结合使用。

1.查询选修了‘2’号课程的学生的学号

select Sno sno from SC where Cno='2'

2.查询Liyong选修的课程成绩

select Grade grade from student,SC where Sname='Liyong' and Student.sno=Sc.Sno
Select grade from sc join student on student.sno=sc.sno where sname=”Liyong”

3.查询选修课程名称Math的学生学号

select Sno sno from Course,SC where Cname='Math' and Course.Cno=Sc.Cno
Select distinct sc.sno from sc join course on course.cno=sc.cno where cname=”Math”

猜你喜欢

转载自www.cnblogs.com/junfblog/p/12766009.html