当前位置:操作系统 > Unix/Linux >>

inner join、left join、right join中where和and的作用

inner join、left join、right join中where和and的作用
 
1、内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现
2、外连接: 包括 
 (1)左外连接 (左边的表不加限制)
   select a.studentno, a.studentname, b.classname
   from students a, classes b where a.classid = b.classid(+);
 (2)右外连接(右边的表不加限制)
   select a.studentno, a.studentname, b.classname
   from students a, classes b where a.classid(+) = b.classid

 

 (3)全外连接(左右两表都不加限制)
即:
左连接显示左边全部的和右边与左边相同的 
右连接显示右边全部的和左边与右边相同的 
内连接是只显示满足条件的! 
 
3.inner join(等值连接) 只返回两个表中联结字段相等的行,where和and条件都对整体查询结果有影响。
 

 
 
4.left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录,right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录,这里一并讨论:
where条件可以对整体查询结果进行筛选,而and只会对连接的表进行筛选。
 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,