使用的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子句中限制左边表的取值时出现非期望的结果的更多相关文章

  1. pdm 中怎么修改表的Name值时使Code值不变

    修改方法:PowerDesign中的选项菜单里修改,在[Tool]-->[General Options]->[Dialog]->[Operating modes]->[Nam ...

  2. jQuery中设置form表单中action值与js有什么不同。。。。

    jQuery中设置form表单中action值与js有什么不同.... HTML代码如下: <form action="" method="post" i ...

  3. springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序

    springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序 http://www.360doc.com/content/14/03 ...

  4. 关于readdir返回值中struct dirent.d_type的取值有关问题(转)

    关于readdir返回值中struct dirent.d_type的取值问题 原网页链接 http://www.gnu.org/software/libc/manual/html_node/Direc ...

  5. jQuery中设置form表单中action值的方法

    jQuery中设置form表单中action值的方法 (2011-03-17 10:18:19) 转载▼ 标签: 杂谈   html代码: <form id="myFormId&quo ...

  6. java中int,float,long,double取值范围,内存泄露

    java中int,float,long,double取值范围是多少? 写道 public class TestOutOfBound { public static void main(String[] ...

  7. Mybatis映射文件中#取值时指定参数相关规则

    Mybatis映射文件中#取值时指定参数相关规则 在#{}中,除了需要的数值外,还可以规定参数的一些其他规则. 例如:javaType,jdbcType,mode(存储过程),numericScale ...

  8. C语言中 指针、引用和取值

    指针是一个存储计算机内存地址的变量.从指针指向的内存读取数据称作指针的取值.指针可以指向某些具体类型的变量地址,例如int.long和double.指针也可以是void类型.NULL指针和未初始化指针 ...

  9. C#中hashtable的赋值、取值、遍历、排序操作

    一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,其 ...

随机推荐

  1. BICEP单元测试——随机四则运算升级版

    一.测试方法 6个值得测试的具体部位: Right-结果是否正确? B-是否所有的边界条件都是正确的? I-能查一下反向关联吗? C-能用其他手段交叉检查一下结果吗? E-你是否可以强制错误条件发生? ...

  2. EF 5 最佳实践白皮书

    Performance Considerations for Entity Framework 5 By David Obando, Eric Dettinger and others Publish ...

  3. FineUI 基于 ExtJS 的专业 ASP.NET 控件库

    FineUI 基于 ExtJS 的专业 ASP.NET 控件库 http://www.fineui.com/

  4. metasploit模块字典爆破tomcat

    祭出神器MSF 再用auxiliary/scanner/http/tomcat_mgr_login 这个辅助模块爆破下弱口令 这里就用模块自带的字典吧   然后简单配置下.RUN 需要自己定义字典的话 ...

  5. 在ubuntu 12.04 x64下编译hadoop2.4

    自己编译hadoop:x64 1.安装依赖包 sudo apt-get install g++ autoconf automake libtool cmake zlib1g-dev pkg-confi ...

  6. C指针-数组和指针的归一

    int bArr[] = {1,2,3}; int *iarr = bArr; *iarr = 6; printf("%d\n",*iarr); printf("%d\n ...

  7. PHP 正则表达式匹配中文字符

    例如在 MySQL 的 bin-log 文件中选取特定的数据库语句来恢复数据时,只要选出某个库的 INSERT INTO 操作(去掉了多余信息,只列出 SQL 语句) INSERT INTO `crm ...

  8. js 事件大全

    Js事件大全一般事件 事件 浏览器支持 描述onClick IE3|N2|O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击onDblClick IE4|N4|O 鼠标双击事件onMouseDo ...

  9. 如何在spring容器开始后,和销毁前,执行一些操作

    转:参考文档:资料链接

  10. PyInstaller打包步骤简记

    pyinstaller 下载地址:http://www.pyinstaller.org/ 下载后用cmd进入解压文件夹 python setup.py install 安装. 最近用pyinstall ...