LEFT JOIN
LEFT JOIN 关键字会从左表那里返回所有的行,即使在右表中没有匹配的行。
即LEFT JOIN 的 ON 条件不会对数据行造成影响

RIGHT JOIN
RIGHT JOIN 关键字会从右表那里返回所有的行,即使在左表中没有匹配的行。

INNER JOIN 
INNER JOIN 关键字会从右表那里返回所有的行,即使在左表中没有匹配的行。

INNER JOIN 的ON 条件会对数据行进行筛选

因此 INNER JOIN的 ON条件 放在ON后 或 WHERE后是一样的效果

从论坛里抄一句过来:

on是连接条件, where是过滤条件。

对内连接来说, 二者等价。

对外连接来说,
on影响侧输入的输出, 合连接条件则输出相应列值,不合则输出null, 对主输入无影响。
where影响结果集。

on是连接条件, where是过滤条件。

对内连接来说, 二者等价。

对外连接来说,
  on影响侧输入的输出, 合连接条件则输出相应列值,不合则输出null, 对主输入无影响。
  where影响结果集。

select * from ta a left join tb on a.id=b.id and b.n is null
此语句输出a表所有行,对于b表的列,当id=a.id且n为null时才会有输出。

select * from ta a left join tb on a.id=b.id where b.n is null
只有b.n为null的行,且a表中存在id=b.id时,才输出,符则a表的行也被过滤

on是连接条件, where是过滤条件。

对内连接来说, 二者等价。

对外连接来说,
  on影响侧输入的输出, 合连接条件则输出相应列值,不合则输出null, 对主输入无影响。
  where影响结果集。

select * from ta a left join tb on a.id=b.id and b.n is null
此语句输出a表所有行,对于b表的列,当id=a.id且n为null时才会有输出。

select * from ta a left join tb on a.id=b.id where b.n is null
只有b.n为null的行,且a表中存在id=b.id时,才输出,符则a表的行也被过滤

on是连接条件, where是过滤条件。

对内连接来说, 二者等价。

对外连接来说,
  on影响侧输入的输出, 合连接条件则输出相应列值,不合则输出null, 对主输入无影响。
  where影响结果集。

select * from ta a left join tb on a.id=b.id and b.n is null
此语句输出a表所有行,对于b表的列,当id=a.id且n为null时才会有输出。

select * from ta a left join tb on a.id=b.id where b.n is null
只有b.n为null的行,且a表中存在id=b.id时,才输出,符则a表的行也被过滤

on是连接条件, where是过滤条件。

对内连接来说, 二者等价。

对外连接来说,
  on影响侧输入的输出, 合连接条件则输出相应列值,不合则输出null, 对主输入无影响。
  where影响结果集。

select * from ta a left join tb on a.id=b.id and b.n is null
此语句输出a表所有行,对于b表的列,当id=a.id且n为null时才会有输出。

select * from ta a left join tb on a.id=b.id where b.n is null
只有b.n为null的行,且a表中存在id=b.id时,才输出,符则a表的行也被过滤

SQLServer inner join,left join,right join,outer join 备忘备忘的更多相关文章

  1. SQL中inner join、outer join和cross join的区别

    对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...

  2. sqlite数据库执行full outer join

    sqlite数据库执行full outer join时提示:RIGHT and FULL OUTER JOINs are not currently supported. sqlite数据库不支持(+ ...

  3. MySql Outer Join 简单化

    查询from语句中的Outer Join可以在多种情况下被简化: 在解析阶段,右外连接操作可以被转变为等下ode值包含left join的操作,在一般情况下,转变: (T1, ...) RIGHT J ...

  4. 【转载】SQL中inner join、outer join和cross join的区别

    对于SQL中inner join.outer join和cross join的区别很多人不知道,我也是别人问起,才查找资料看了下,跟自己之前的认识差不多, 如果你使用join连表,缺陷的情况下是inn ...

  5. hive中left join、left outer join和left semi join的区别

    先说结论,再举例子.   hive中,left join与left outer join等价.   left semi join与left outer join的区别:left semi join相当 ...

  6. oracle 内连接(inner join)、外连接(outer join)、全连接(full join)

    转自:https://premier9527.iteye.com/blog/1659689 建表语句: create table EMPLOYEE(EID NUMBER,DEPTID NUMBER,E ...

  7. “,”、“natural join”、“natural left outer join”、“natural right outer join”的用法总结

    “,”:代表笛卡尔积: “natural join”:代表自然连接,即同名列等值连接: “natural left outer join”:表示左外连接: “natural right outer j ...

  8. SQL中inner join,outer join和cross join的区别

    使用join连表,缺陷的情况下是inner join,开发中使用的left join和right join属于outer join,outer join还包括full join 现有两张表,Table ...

  9. left outer join的on不起作用

    left outer join的on不起作用 Why and when a LEFT JOIN with condition in WHERE clause is not equivalent to ...

  10. Oracle Partition Outer Join 稠化报表

    partition outer join实现将稀疏数据转为稠密数据,举例: with t as (select deptno, job, sum(sal) sum_sal from emp group ...

随机推荐

  1. 团体程序设计天梯赛-练习集-L1-047. 装睡

    L1-047. 装睡 你永远叫不醒一个装睡的人 —— 但是通过分析一个人的呼吸频率和脉搏,你可以发现谁在装睡!医生告诉我们,正常人睡眠时的呼吸频率是每分钟15-20次,脉搏是每分钟50-70次.下面给 ...

  2. PAT_A1136#A Delayed Palindrome

    Source: PAT_A1136 A Delayed Palindrome (20 分) Description: Consider a positive integer N written in ...

  3. C#第十二节课

    数组 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Th ...

  4. [luogu4158 SCOI2009] 粉刷匠(dp)

    传送门 Solution 把状态都记上暴力转移即可 Code //By Menteur_Hxy #include <queue> #include <cmath> #inclu ...

  5. java中的replaceAll方法注意事项

    replaceAll和replace方法参数是不同的,replace的两个参数都是代表字符串,replaceAll的第一个参数是正则表达式 replaceAll中需要注意的特殊字符: \ == \\\ ...

  6. SPOJ 1812 LCS2 - Longest Common Substring II (后缀自动机、状压DP)

    手动博客搬家: 本文发表于20181217 23:54:35, 原地址https://blog.csdn.net/suncongbo/article/details/85058680 人生第一道后缀自 ...

  7. Photoshop教程

    Photoshop百科 Adobe Photoshop,简称“PS”,是由Adobe Systems开发和发行的图像处理软件. Photoshop主要处理以像素所构成的数字图像.使用其众多的编修与绘图 ...

  8. 做acm 需要学的算法

    做acm 需要学的算法 转一个搞ACM需要的掌握的算法.  要注意,ACM的竞赛性强,因此自己应该和自己的实际应用联系起来.  适合自己的才是好的,有的人不适合搞算法,喜欢系统架构,因此不要看到别人什 ...

  9. Linux去重命令uniq(转)

    注意:需要先排序sort才能使用去重. Linux uniq命令用于检查及删除文本文件中重复出现的行列. uniq可检查文本文件中重复出现的行列. 语法 uniq [-cdu][-f<栏位> ...

  10. 优酷土豆资深工程师:MySQL高可用之MaxScale与MHA

    本文根据DBAplus社群第67期线上分享整理而成 本次分享主要包括以下内容: 1.MySQL高可用方案 2.为什么选择MHA 3.读写分离方案的寻找以及为什么选择Maxscale 一.MySQL  ...