格式 select f1.a, f2.b form f1 left jion f2 on ....

注意:左边的查询部分只能有select和from,不能出现where order by等。若有必须在外嵌套一层 select

On 后面的条件只影响入选的f2.b字段有没有值,不影响总行数

(2016.9.9 上面说法错误!可以写where和order,写在on语句之后就行)

2017.10.25 两张表都带where条件的left join 写法

写法1: 左表的where条件写在on语句后,右表的where条件写在on里,或者二者颠倒,结果不变

   select f1.chart_type_id prm_id, f2.chart_type_id
            from TERMINAL_CHART_TYPE f1
            left join TERMINAL_CHART_TYPE f2
            on  f2.type_name='航路点坐标'
            where f1.type_name='标准仪表进场图'

写法2:上述where写法颠倒

    select f1.chart_type_id prm_id, f2.chart_type_id
            from TERMINAL_CHART_TYPE f1
            left join TERMINAL_CHART_TYPE f2
            on  f1.type_name='标准仪表进场图'
            where f2.type_name='航路点坐标'

写法3:用嵌套select写右表,右表where条件写在嵌套sql中

    select f1.chart_type_id prm_id, f2.chart_type_id
            from TERMINAL_CHART_TYPE f1
            left join (select * from TERMINAL_CHART_TYPE f2 where f2.type_name='航路点坐标') f2
            on 1=1
            where f1.type_name='标准仪表进场图'

结果都是:4 32

2015.1.8 Left join 左连接的更多相关文章

  1. mysql left join 左连接查询关联n多张表

    left join 左连接即以左表为基准,显示坐标所有的行,右表与左表关联的数据会显示,不关联的则不显示.关键字为left join on. **基本用法如下: select table a left ...

  2. linq join 左连接 leftjoin 多个on条件 where 条件

    var haveChange = from newScore in newScoreList join oldScore in oldScoreList on new{newScore.ExamId, ...

  3. Linq Left Join;linq左连接 (转载)

    来源 https://www.cnblogs.com/xinjian/archive/2010/11/17/1879959.html 准备一些测试数据,如下: use Test Create tabl ...

  4. SQLServer学习笔记<> 表连接查询----交叉连接、内连接、左连接、右连接

    (1)交叉连接(cross join)即我们所说的笛卡尔积.查询出满足两张表所有的记录数,A(3条记录),B(9条记录),A*B(27条记录). 比如:雇员表(HR.employees)和货运公司(S ...

  5. SQL: 左连接,右连接,内连接,左外连接,右外连接,完全连接

    例子: ---------------------- --------------------------- a表 id name b表 id job parent_id 1 张三           ...

  6. 数据库中的左连接(left join)和右连接(right join)区别

    Left Join / Right Join /inner join相关 关于左连接和右连接总结性的一句话: 左连接where只影向右表,右连接where只影响左表. Left Join select ...

  7. 数据库左连接left join、右连接right join、内连接inner join on 及 where条件查询的区别

    join on 与 where 条件的执行先后顺序: join on 条件先执行,where条件后执行:join on的条件在连接表时过滤,而where则是在生成中间表后对临时表过滤 left joi ...

  8. Oracle 左连接、右连接、全外连接、(+)号作用、inner join(等值连接) (转载)

    Oracle  外连接 (1)左外连接 (左边的表不加限制)       (2)右外连接(右边的表不加限制)       (3)全外连接(左右两表都不加限制) 外连接(Outer Join) oute ...

  9. SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)

    SQL 连接 JOIN 例解.(左连接,右连接,全连接,内连接,交叉连接,自连接) 最近公司在招人,同事问了几个自认为数据库可以的应聘者关于库连接的问题,回答不尽理想-现在在这写写关于它们的作用假设有 ...

随机推荐

  1. eclipse和myeclipse的配置(基于工作空间)

    eclipse和myeclipse的配置是基于工作空间的,一旦工作空间发生改变,就需要重新配置. 以eclipse为例,新建工作空间后,选择Window--->Preferences: 1.在W ...

  2. spark学习2-1(hive1.2安装)

    由于前面安装版本过老,导致学习过程中出现了很多问题,今天安装了一个新一点的版本.安装结束启动时遇到一点问题,记录在这里. 第一步:hive-1.2安装 通过WinSCP将apache-hive-1.2 ...

  3. java 实现HTTP连接(HTTPClient)

    在实习中,使用到了http连接,一直理解的很模糊,特地写个分析整理篇.分析不到位的地方请多多指教. Http 目前通用版本为 http 1.1 . Http连接大致分为2种常用的请求——GET,POS ...

  4. DelphiXE_Android

    1. http://download.csdn.net/detail/gx15941883020/8104761 2. http://bbs.2ccc.com/topic.asp?topicid=45 ...

  5. rapidjson代码封装类

    rapidjson代码封装类 以下代码封装了rapidjson增删改查等基本操作: /********************************************************* ...

  6. dom 兼容性问题1_节点部分

    AS : ECMAScript xml . html js组成: 1,ECMAScript : 是Javascript的核心标准.同时也是一个解释器. 2,DOM: document object m ...

  7. python 矩阵转置transpose

    在读图片时,会用到这么的一段代码: image_vector_len = np.prod(image_size)#总元素大小,3*55*47 img = Image.open(path)       ...

  8. python3 使用pymysql

    #! /usr/bin/env python3 # coding = utf-8 import random import pymysql # 连接数据库函数 def connDB(data): co ...

  9. The tag handler class for "c:set"(org.apache.taglibs.standard.tag.rt.core.UrlTag)was not found on the Java Build Path

    1.源码: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> < ...

  10. HANA 存储过程

    You can develop secure procedures using SQLScript in SAP HANA by observing the following recommendat ...