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. Ubuntu下设置 nginx php-fpm 自动启动 rc.local

    编辑 root@ubuntu:/usr/sbin# vim /etc/init.d/rc.local /usr/sbin/php-fpm /usr/sbin/nginx 保存!

  2. 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying 题解

    P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...

  3. 洛谷P2029跳舞

    题目 DP, 用的\(dp[i][j]\)表示\(i\)之前的数选了\(j\)个得到的最大结果,然后状态转移方程应该是 \[if (j \% t == 0)~~dp[i][j] = max(dp[i] ...

  4. P5597 【XR-4】复读

    枚举终点u,把路径(1,u)压起来(不考虑u的子树),并起来之后暴力

  5. D3.js的v5版本入门教程(第十章)

    在这一章我们干点有趣的事——让我们上一章绘制的图表动起来,这样岂不是很有意思 为了让图表动起来,我们还是需要以下新的知识点 .attr(xxx) .transition() .attr(xxx),tr ...

  6. 2015-2016-2《Java程序设计》团队博客2

     简易画图板介绍 一.功能结构图 二.主类设计 1.总体设计:在设计简易画图板时,根据程序功能的分类,包含了十二个文件,包括SimpleDraw.java,MenuContainer.java,Dra ...

  7. 什么是CN2线路

      CN2全称为中国电信下一代承载网,英文Chinatelecom Next Carrier Network,缩写为CNCN,进一步缩写为CN2. CN2线路的优势在哪里 CN2作为“精品网络项目”被 ...

  8. visual studio 无添加视图 选项

    我是因为 UserController未继承 Controller

  9. xadmin插件

    from django.http import HttpResponse from xadmin.plugins.actions import BaseActionView class test(Ba ...

  10. Tomcat 配置虚拟目录以及虚拟主机

    目录 虚拟目录 虚拟主机 虚拟目录 虚拟目录的功能 一般情况下,我们的打包后的项目都是放到tomcat/webapps目录下的,然后通过localhost:8080/project_name这个链接进 ...