DB2-6> 连接

关于 db2 连接查询的总结


 


A表:
 


db2 => select * from administrator.students
 
ID          NAME                                               STRID                                              SEX
----------- -------------------------------------------------- -------------------------------------------------- ----------
          0 王二小                                             1001                                              
          2 武三郎                                             1002                                              
          3 裴元庆                                             1003                                              
          4 程咬金                                             1006                                              
 


B表:
 


 
 


db2 => select * from administrator.studentinformantion
 
ID                   GRADE                STRID
-------------------- -------------------- --------------------
                   1 55                                   1001
                   2 65                                   1002
                   3 96                                   1003
                   4 55                                   1005
 


 
 


 


内连接
 


inner join 连接查询:
inner join 假定两张表中有不同的结果集。若是俩张表的数据中。有相互不匹配的数据,则不会出现的结果集中
 
经过试验,内连接 是不会把相互不否和的数据出现在结果集中的。
代码所示:
select * from students s,studentinformantion s1 where s1.strid=s.strid
---inner join 
 select * from administrator.students s join administrator.studentinformantion s1 on s.strid=s1.strid
 
外连接   outer join
 
 
外连接把不拼配的也放在结果集中。没有的那一个用 NULL来代替。
 
外连接 包括,全部外连接(full outer join ) 右外连接 right outer join  左外连接 left outer join 三种类型。
 
 1 全部外连接
 
示例:
左外连接:
 

db2 => select * from administrator.students s left outer join administrator.studentinformantion s1 on s1.strid=s.strid

右外连接
 
 
db2 => select * from administrator.students s right join administrator.studentinformantion s1 on s1.strid=s.strid

全连接
 
db2 => select * from administrator.students s full outer join administrator.studentinformantion s1 on s1.strid=s.strid

3》交叉连接 
 

db2 => select * from administrator.students s cross join administrator.studentinformantion s1

交叉连接,是有第一个表和第二个表的每一行拼接成一个新表
4》星型连接 (STAR join
暂无总结。

 

posted @ 2017-05-09 20:38  Coeus.酱油帝  阅读(127)  评论(0)    收藏  举报