1、等值连接与非等值连接
当连接运算符为等号时为等值连接,当为其他运算符时为非等值连接。
select studentno,sname
from student,teach_class,teacher
where student.classno=teach_class.classno
and teach_class.teacherno=teacher.teacherno
and teacher.tname='刘老师'
2、自身连接
连接操作发生在一个表以其自身进行连接。
select teacher.*
from teach_class t1,teach_class t2,teacher
where t1.teacherno=teacher.teacherno
and t2.teacherno=teacher.teacherno
and t1.courseno='c1'
and t2.courseno='c2'
3、外连接
在连接操作中被舍弃的元组成为“悬浮元组”。
左外连接:只保留左边关系的悬浮元组。
右外连接:只保留右边关系的悬浮元组。
select course.*
from course left outer join score on (course.courseno=score.courseno)
where score.studentno is null
4、嵌套查询
ANY:某个值
ALL: 所有值
select studentno,sname,classno
from student s1
where point>(
select AVG(point)
from student s2
where s1.classno=s2.classno
)