关于在left join的on子句中限制左边表的取值时出现非期望的结果
使用的SQL大概是这样的:
select * from A left join B on A.id=B.id and A.id>10; --错误的使用
我们期望的结果集应该是 A中的id>10,但是实际上A.id>10 这个限制条件并没有起作用。
应该改成如下的这种形式:
select * from A left join B on A.id=B.id where A.id>10;--正确的使用
这是在oracle的官方文档中找到的相关说明:
left outer join
The result of a left outer join for table A and B contains all records of the left table A,
even if the join condition does not match a record in the right table B. For example, if
you perform a left outer join of employees (left) to departments (right), and if some
employees are not in a department, then the query returns rows from employees
with no matches in departments.
这是在 《Database System Concepts》这本书中找到的相关说明:
The right outer join is symmetric with the left outer join: It pads tuples
from the right relation that did not match any from the left relation with nulls and
adds them to the result of the natural join. In Figure 6.18, tuple (58583, null, null,
null, null, Califieri, History, 62000), is such a tuple. Thus, all information from the
right relation is present in the result of the right outer join.
大致的意思是,left join的结果集一定会包含左边表的所有记录。同理,right join一定会包含右边表的所有记录。
所以,使用时应该只在on子句中包含关联条件,单独对某个表的限制应该放到where子句中。
只是不知道,如果在left join的on子句中单独限制右边的表会不会有利于减少中间表的大小。
关于在left join的on子句中限制左边表的取值时出现非期望的结果的更多相关文章
- pdm 中怎么修改表的Name值时使Code值不变
修改方法:PowerDesign中的选项菜单里修改,在[Tool]-->[General Options]->[Dialog]->[Operating modes]->[Nam ...
- jQuery中设置form表单中action值与js有什么不同。。。。
jQuery中设置form表单中action值与js有什么不同.... HTML代码如下: <form action="" method="post" i ...
- springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序 http://www.360doc.com/content/14/03 ...
- 关于readdir返回值中struct dirent.d_type的取值有关问题(转)
关于readdir返回值中struct dirent.d_type的取值问题 原网页链接 http://www.gnu.org/software/libc/manual/html_node/Direc ...
- jQuery中设置form表单中action值的方法
jQuery中设置form表单中action值的方法 (2011-03-17 10:18:19) 转载▼ 标签: 杂谈 html代码: <form id="myFormId&quo ...
- java中int,float,long,double取值范围,内存泄露
java中int,float,long,double取值范围是多少? 写道 public class TestOutOfBound { public static void main(String[] ...
- Mybatis映射文件中#取值时指定参数相关规则
Mybatis映射文件中#取值时指定参数相关规则 在#{}中,除了需要的数值外,还可以规定参数的一些其他规则. 例如:javaType,jdbcType,mode(存储过程),numericScale ...
- C语言中 指针、引用和取值
指针是一个存储计算机内存地址的变量.从指针指向的内存读取数据称作指针的取值.指针可以指向某些具体类型的变量地址,例如int.long和double.指针也可以是void类型.NULL指针和未初始化指针 ...
- C#中hashtable的赋值、取值、遍历、排序操作
一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,其 ...
随机推荐
- marquee-:模拟弹幕
marquee:基本已被弃用!!1 可以模拟弹幕效果 1.方向:direction up right left down ...
- csipsimple 出现单通情况
今天在测试voip电话时,突然打不通了和windows端也不通,boss发怒了. 经过排查,发现设置G729编码 //设置G729编码 prefs.setCodecPriority("g72 ...
- 移动手机端H5无缝间歇平滑向上滚动js代码
在没结合css3的transform实现平滑过渡前,我都是用的jquery的animate方法,此方法在PC端基本看不出来有稍微卡顿的现象,但是在性能不高的手机上使用该方法,就会有明显的卡顿现象,不够 ...
- 利用win7usb-dvdtool工具u盘安装win7
首先介绍下背景:我的电脑是两块盘,然后系统是ubuntu,但是因为最近觉得linux不怎么用了,所以想装回windows,这个过程遇到好多麻烦,主要是两方面的 1.不识别u盘做的启动盘2.两块硬盘导致 ...
- EJB之Timer
EJB Timer 要么: Annotation @Schedule 或者方法前声明@Timeout 要么: 在部署描述中定义timeout-method 如果是使用@Schedule, Timer在 ...
- crontab执行时间和系统时间不一致
最近发现一个非常奇怪的问题,症状如下: crontab 定时任务 配置时间 是 10 5 * * * (每日凌晨5点10分执行) 运行脚本时间却是 18:10左右 Dec 24 05:10:01 ht ...
- 移动端rem 适配
在 index.html 中添加如下代码 <script> let html = document.documentElement; window.rem = html.getBoundi ...
- 本地代码如何通过TortoiserGit提交到GitHub
昨天博文给大家讲解了一下如何本地安装TortoiseGit http://www.cnblogs.com/xinlj/p/5978730.html,今天为大家讲一下如何通过TortoiseGit将本地 ...
- Emacs 16进制模式
http://blog.163.com/lan_ne/blog/static/1926701702012112272840545/ ALT+X hexl-mode 进入16进制模式 在这一模式,直 ...
- Oracle merge into
Oracle中Merge into用法总结 文件来源:(http://blog.csdn.net/yuzhic/article/details/1896878) 有一个表T,有两个字段a.b,我们想在 ...