orcale 查询语句(多种查询语句)

--等值连接

1.select * from student inner join sc on student.sno=sc.sno

2.select * from student join sc on student.sno=sc.sno

orcale 查询语句(多种查询语句)

--笛卡尔集(全连接)

   --省略连接条件,连接条件无效,两表中的所有行互相连接且两表条数相乘就是总条数;

  1.select * from student CROSS JOIN sc

  2.select * from student,sc

orcale 查询语句(多种查询语句)

--满链接

  --FULL JOIN 关键字会从两表那里返回所有的行。如果 "student" 中的行在表 "sc" 中没有匹配,

  --或者如果 "sc" 中的行在表 "student" 中没有匹配,这些行同样会列出

select * from student

full join sc

on sc.sno=student.sno

orcale 查询语句(多种查询语句)

--左连接

  --”student“中的行在表 "sc" 中没有匹配的列也会列出来

  1.select * from student

    LEFT OUTER JOIN sc ON sc.sno=student.sno;

  2. select * from student,sc where sc.sno(+)=student.sno;

orcale 查询语句(多种查询语句)

--右连接

  --“sc“中的行在表 "student" 中没有匹配的列也会列出来

  1.select * from student

    right OUTER JOIN sc ON sc.sno=student.sno;

  2. select * from student,sc where sc.sno=student.sno(+);

orcale 查询语句(多种查询语句)

--自然连接  会以两个表中具有相同名字的列为条件创建等值连接)

select * from student NATURAL  join sc

--多表连接:

  1.select * from  student,COURSE,sc

    where student.sno=sc.sno and sc.cno=COURSE.cno

  2.select * from  student

    join   sc

    on     student.sno=sc.sno

    join   COURSE

    on     sc.cno=COURSE.cno

  3.select * from student

    join sc

    using(sno)

    join COURSE

using(cno)

orcale 查询语句(多种查询语句)

 

 

注: 1.using 可以给多个连接值,如using(column1,column2)

     2.using 不可以给表指定表别名;

     3.where 一般跟 from  ,on 一般跟 join;