连接操作可以是一个表与自身进行的连接,这时候注意需要为表创建别名
课程信息表
课程号 课程名 先修课程号 课程学分
create table Course (
Cno int,
Cname char(20),
Cpno int,
Ccredit int,
primary key (Cno)
);
insert into Course(Cno, Cname, Cpno, Ccredit)
values
(1, '数据库', 5, 4),
(2, '数学', null, 2),
(3, '信息系统', 1, 4),
(4, '操作系统', 6, 3),
(5, '数据结构', 7, 4),
(6, '数据处理', null, 2),
(7, 'PASCAL语言', 6, 4);
查询每门课对应的先修课程
select first.Cno, first.Cname '课程名', second.Cname '先修课程'
from Course first, Course second
where first.Cpno = second.Cno;