sql中left join on where区别剖析
select from tb1 left join tb2 on tb1.xx=tb2.xx and tb2.xxxx=5
先筛选tb2.xxxx=5 再把tb1与筛选后的临时表进行左连接。
select from tb1 left join tb2 on tb1.xx=tb2.xx where tb2.xxxx=5
先把tb1与tb2进行左连接,连接后产生的临时表筛选出tb2.xxxx=5的记录。
SELECT * FROM tb1; id name age ------ ------- -------- 1 liuchao 34 2 lilijun 28 3 chengyu 44
SELECT * FROM tb2;
id name task ------ ------- -------- 1 liuchao work 2 liuchao study 3 lilijun study
SELECT * FROM tb1 LEFT JOIN tb2 ON tb1.name=tb2.name AND tb2.`name`='liuchao';
id name age id name task ------ ------- ------ ------ ------- -------- 1 liuchao 34 1 liuchao work 1 liuchao 34 2 liuchao study 2 lilijun 28 (NULL) (NULL) (NULL) 3 chengyu 44 (NULL) (NULL) (NULL)
SELECT * FROM tb1 LEFT JOIN tb2 ON tb1.name=tb2.name WHERE tb2.`task` IS NOT NULL;
id name age id name task ------ ------- ------ ------ ------- -------- 1 liuchao 34 1 liuchao work 1 liuchao 34 2 liuchao study 2 lilijun 28 3 lilijun study
sql中left join on where区别剖析的更多相关文章
- SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...
- SQL中关于Join、Inner Join、Left Join、Right Join、Full Join、On、 Where区别
前言: 今天主要的内容是要讲解SQL中关于Join.Inner Join.Left Join.Right Join.Full Join.On. Where区别和用法,不用我说其实前面的这些基本SQL语 ...
- 【转载】SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别很多人不知道,我也是别人问起,才查找资料看了下,跟自己之前的认识差不多, 如果你使用join连表,缺陷的情况下是inn ...
- sql中的join
首先准备数据 有以下数据,三张表:role(角色表).hero(英雄表).skill(技能表),我们以英雄联盟的数据做示例 一个hero对应一个role(我们这里暂定) 一个role可以对应多个her ...
- SQL中ON和WHERE的区别
SQL中ON和WHERE的区别 - 邃蓝星空 - 博客园 https://www.cnblogs.com/guanshan/articles/guan062.html
- LINQ TO SQL 中的join(转帖)
http://www.cnblogs.com/ASPNET2008/archive/2008/12/21/1358152.html join对于喜欢写SQL的朋友来说还是比较实用,也比较容易接受的东西 ...
- SQL中的Join和Where的区别
一.sql语句中left join.inner join中的on与where的区别 0.各种join操作的概念和作用 left join :左连接,返回左表中所有的记录以及右表中连接字段相等的记录. ...
- SQL中INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN区别
sql中的连接查询有inner join(内连接).left join(左连接).right join(右连接).full join(全连接)四种方式,它们之间其实并没有太大区别,仅仅是查询出来的结果 ...
- SQL中的join操作总结(非常好)
1.1.1 摘要 Join是关系型数据库系统的重要操作之一,SQL Server中包含的常用Join:内联接.外联接和交叉联接等.如果我们想在两个或以上的表获取其中从一个表中的行与另一个表中的行匹配的 ...
随机推荐
- Linux常用的50个命令
50个最常用的Unix/Linux命令 2014-08-20 这篇文章翻译自http://www.thegeekstuff.com/2010/11/50-linux-commands/这些都是一些很常 ...
- Jenkins构建shell
#!/bin/bash cd Labwfcm git pull cd wfcm-api mvn clean package cd target mv wfcm-api.war wfcm-api.war ...
- window.location与window.open()的区别
"top.location.href"是最外层的页面跳转"window.location.href"."location.href"是本页面 ...
- Java8_01_新特性概述
一.前言 二.
- Database项目中关于Procedure sp_refreshsqlmodule_internal的错误
最近项目中发现一怪问题,使用DB项目发布数据库时,总提示 “(110,1): SQL72014: .Net SqlClient Data Provider: Msg 1222, Level 16, S ...
- 使用第三方图表工具——Chart.js
效果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="U ...
- 21天学通C++_Day4
0.迭代器 昨天晚上3G移动通信实验的时候,需要写一些简单的C程序,用到for循环的时候,发现在不同的for循环中,若定义标识符相同的变量名时,会有报错,环境是VC6: 可是一想到在for语句声明的迭 ...
- LeetCode 616. Add Bold Tag in String
原题链接在这里:https://leetcode.com/problems/add-bold-tag-in-string/description/ 题目: Given a string s and a ...
- openfaas 了解
1. 官方介绍 OpenFaaS (Functions as a Service) is a framework for building serverless functions with Dock ...
- 常用DNS列表(电信、网通)
电信 DNS 列表 -- 共 32 条 (按拼音排序) 电信 A安徽 202.102.192.68 202.102.199.68 电信 A澳门 202.175.3.8 202.175.3.3 ...