CREATE TABLE `j1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `c1` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE `j2` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `c1` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

mysql> select * from j1;
+----+-------+
| id | c1    |
+----+-------+
|  1 | user1 |
|  2 | user2 |
|  3 | user3 |
|  4 | user4 |
|  5 | user5 |
+----+-------+
5 rows in set (0.01 sec)

mysql> select * from j2;
+----+--------------+
| id | c1           |
+----+--------------+
|  1 | user_detail1 |
|  3 | user_detail3 |
|  4 | user_detail4 |
|  6 | user_detail6 |
|  8 | user_detail8 |
+----+--------------+
5 rows in set (0.00 sec)

mysql> select * from j1 left join j2 on j1.id = j2.id;
+----+-------+------+--------------+
| id | c1    | id   | c1           |
+----+-------+------+--------------+
|  1 | user1 |    1 | user_detail1 |
|  2 | user2 | NULL | NULL         |
|  3 | user3 |    3 | user_detail3 |
|  4 | user4 |    4 | user_detail4 |
|  5 | user5 | NULL | NULL         |
+----+-------+------+--------------+
5 rows in set (0.00 sec)

mysql> select * from j1 right join j2 on j1.id = j2.id;
+------+-------+----+--------------+
| id   | c1    | id | c1           |
+------+-------+----+--------------+
|    1 | user1 |  1 | user_detail1 |
|    3 | user3 |  3 | user_detail3 |
|    4 | user4 |  4 | user_detail4 |
| NULL | NULL  |  6 | user_detail6 |
| NULL | NULL  |  8 | user_detail8 |
+------+-------+----+--------------+
5 rows in set (0.00 sec)

mysql> select * from j1 inner join j2 on j1.id = j2.id;
+----+-------+----+--------------+
| id | c1    | id | c1           |
+----+-------+----+--------------+
|  1 | user1 |  1 | user_detail1 |
|  3 | user3 |  3 | user_detail3 |
|  4 | user4 |  4 | user_detail4 |
+----+-------+----+--------------+
3 rows in set (0.00 sec)

mysql> desc select * from j1 left join j2 on j1.id = j2.id where j2.id is not null;
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
| id | select_type | table | partitions | type   | possible_keys | key     | key_len | ref          | rows | filtered | Extra       |
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
|  1 | SIMPLE      | j2    | NULL       | ALL    | PRIMARY       | NULL    | NULL    | NULL         |    5 |    80.00 | Using where |
|  1 | SIMPLE      | j1    | NULL       | eq_ref | PRIMARY       | PRIMARY | 4       | mytest.j2.id |    1 |   100.00 | NULL        |
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
2 rows in set, 1 warning (0.00 sec)
mysql> desc select * from j2 left join j1 on j1.id = j2.id where j1.id is not null;
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
| id | select_type | table | partitions | type   | possible_keys | key     | key_len | ref          | rows | filtered | Extra       |
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
|  1 | SIMPLE      | j1    | NULL       | ALL    | PRIMARY       | NULL    | NULL    | NULL         |    5 |    80.00 | Using where |
|  1 | SIMPLE      | j2    | NULL       | eq_ref | PRIMARY       | PRIMARY | 4       | mytest.j1.id |    1 |   100.00 | NULL        |
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
2 rows in set, 1 warning (0.00 sec)

JOIN的区别的更多相关文章

  1. sql之left join、right join、inner join的区别

    sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...

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

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

  3. left join 和 left outer join 的区别

    left join 和 left outer join 的区别 通俗的讲:    A   left   join   B   的连接的记录数与A表的记录数同    A   right   join   ...

  4. SQL Server之LEFT JOIN、RIGHT LOIN、INNER JOIN的区别

    很多人刚入门的时候分不清LEFT JOIN.RIGHT LOIN 和 INNER JOIN的区别,对它们的定义比较模糊,今天就简单的介绍一下它们的区别,对于入门的人来说,应该能够帮助你们理解. lef ...

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

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

  6. JAVA多线程之CountDownLatch与join的区别

    首先,我们来看一个应用场景1: 假设一条流水线上有三个工作者:worker0,worker1,worker2.有一个任务的完成需要他们三者协作完成,worker2可以开始这个任务的前提是worker0 ...

  7. sleep、yield、wait、join的区别(阿里面试)

    1.  Thread.sleep(long) 和Thread.yield()都是Thread类的静态方法,在调用的时候都是Thread.sleep(long)/Thread.yield()的方式进行调 ...

  8. 并发编程---互斥锁---互斥锁与join的区别

    互斥锁 互斥锁:就是把多个进程并发,修改成一块共享数据的操作变成串行,保证是一个一个来修改的. 缺点:效率低,加锁过程复杂 优点:增加了安全性 from multiprocessing import ...

  9. sql之left join、right join、inner join的区别,连接自己时的查询结果测试

    sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...

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

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

随机推荐

  1. WinDbg常用命令系列---.effmach

    .effmach (Effective Machine) .effmach命令显示或更改调试器使用的处理器模式. .effmach [MachineType] 参数: MachineType指定调试器 ...

  2. JMeter学习1

    Jmeter的组织方式相对比较扁平,直接是TestPlan(相当于Project),TestPlan下创建的ThreadsGroup(相当于TestCase), Jmeter一个TestPlan也是一 ...

  3. siblings() 方法

    siblings([selected])       简介: 给定一个表示一组DOM元素的jQuery对象,该.siblings()方法允许我们在DOM树中搜索这些元素的兄弟节点,并从匹配的元素构造一 ...

  4. [总结] MSF攻击数据库服务

    0x01 攻击Mysql服务 1.1 目标探测 auxiliary/scanner/mysql/mysql_version 常用于内网中的批量mysql主机发现: 1.2 爆破登录 auxiliary ...

  5. react项目如何运行

    react项目如何运行 一.总结 一句话总结: npm i 安装好package.json的 指定插件后,npm start 启动项目 二.react项目的安装与运行 转自或参考:react项目的安装 ...

  6. Unity3D Substance designer Sub 欧洲小镇场景制作视频教程 中文字幕

    大小6.53G,中文字幕 扫码时备注或说明中留下邮箱 付款后如未回复请至https://shop135452397.taobao.com/ 联系店主

  7. redis 服务器开放给其他电脑连接

    1.云服务器的端口6379开通 2.宝塔服务器上的6379开通 3.修改服务器上的redis配置文件: # bind 127.0.0.1 注释掉daemonize no 改为noprotected-m ...

  8. bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

    工程中引入其他工程的包,由于两个工程中有重名的两个bean,导致在启动时提示如下错误: 根据bean名称在ide中查找,找到这两个重名的类,可以看到由于这两个类使用@Service标注,此时如果不使用 ...

  9. c# winform访问 带有windows身份验证的webservice

    1 将webservice设置为windows身份验证iis10中,要确认已安装windows身份验证在 控制面板 - >打开或关闭Windows功能 - >万维网服务 - >安全性 ...

  10. Spring整合Redis,并配置Jedis连接池

    目录 只言片语 创建redis连接池的配置文件 单机版 spring整合redis(使用JedisPool) 项目中使用示例 集群版 spring整合redis(使用JedisCluster) 项目中 ...