JOIN的区别
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)
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
| 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)
+----+-------------+-------+------------+--------+---------------+---------+---------+--------------+------+----------+-------------+
| 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的区别的更多相关文章
- sql之left join、right join、inner join的区别
sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...
- SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...
- left join 和 left outer join 的区别
left join 和 left outer join 的区别 通俗的讲: A left join B 的连接的记录数与A表的记录数同 A right join ...
- SQL Server之LEFT JOIN、RIGHT LOIN、INNER JOIN的区别
很多人刚入门的时候分不清LEFT JOIN.RIGHT LOIN 和 INNER JOIN的区别,对它们的定义比较模糊,今天就简单的介绍一下它们的区别,对于入门的人来说,应该能够帮助你们理解. lef ...
- 【转载】SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别很多人不知道,我也是别人问起,才查找资料看了下,跟自己之前的认识差不多, 如果你使用join连表,缺陷的情况下是inn ...
- JAVA多线程之CountDownLatch与join的区别
首先,我们来看一个应用场景1: 假设一条流水线上有三个工作者:worker0,worker1,worker2.有一个任务的完成需要他们三者协作完成,worker2可以开始这个任务的前提是worker0 ...
- sleep、yield、wait、join的区别(阿里面试)
1. Thread.sleep(long) 和Thread.yield()都是Thread类的静态方法,在调用的时候都是Thread.sleep(long)/Thread.yield()的方式进行调 ...
- 并发编程---互斥锁---互斥锁与join的区别
互斥锁 互斥锁:就是把多个进程并发,修改成一块共享数据的操作变成串行,保证是一个一个来修改的. 缺点:效率低,加锁过程复杂 优点:增加了安全性 from multiprocessing import ...
- sql之left join、right join、inner join的区别,连接自己时的查询结果测试
sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...
- hive中left join、left outer join和left semi join的区别
先说结论,再举例子. hive中,left join与left outer join等价. left semi join与left outer join的区别:left semi join相当 ...
随机推荐
- mov offset和lea的区别
mov offset和lea的区别 原文地址:https://www.cnblogs.com/fanzi2009/archive/2011/11/29/2267725.html 全局变量取地址用mo ...
- Linux桌面最轻量的Dock之Plank介绍
官方的文档描述 Plank 是“这个星球上最简洁的 dock”.该项目的目的就是仅提供一个 dock 需要的功能,尽管这是很基础的一个库,却可以被扩展,创造其他的含更多高级功能的 dock 程序. 这 ...
- 从一道题浅说 JavaScript 的事件循环
最近看到这样一道有关事件循环的前端面试题: //请写出输出内容 async function async1() { console.log('async1 start'); await async2( ...
- 《RabbitMQ 实战》读书笔记
MQ的好处: 1.业务上接口(系统扩展性变强) 2.性能提升(同步变异步,效率提高,还方便做负载均衡) 3.技术兼容(可以连接各种不同语言的系统,作为粘合剂) 读书笔记: 1.消息队列的应用场景:系统 ...
- 安卓入门教程(十四)-菜单,ActionBar,对话框
已经发表个人公众号 菜单类型 选项菜单(OptionMenu) 子菜单(SubMenu) 上下文菜单(ContextMenu) 方法: public boolean onCreateOptionsMe ...
- 深度讨论i++问题
例题1:下列程序的输出结果是多少? public class Test { static { int x = 5; } static int x, y; public static void main ...
- 38861cba61c66739c1452c3a71e39852.ttf net::ERR_ABORTED 404 (Not Found)
error: http://localhost:63342/clappr-dev/js/38861cba61c66739c1452c3a71e39852.ttf net::ERR_ABORTED 40 ...
- iis启动 服务无法在此时接受控制信息。 (异常来自 HRESULT:0x80070425)
问题描述:每隔一段时间应用程序池就会自动停止. 再次启动就报错:服务无法在此时接受控制信息. (异常来自 HRESULT:0x80070425) 处理办法:同时按下Win+R,运行“services. ...
- 计算电脑所能表示的最大最小值(c++)
C++当中获得现在计算机上所能表示的各种类型(比如int,long int,short int,double,float等)最大最小有两种方法,一种是使用c++预先定义的宏,对于有些编译器可能需要包含 ...
- php 把数字转化为大写中文—升级版
继上篇之后,发现某同事悄悄改了新版本,于是被我偷偷保存起来了,功能一样,不过他的比较短小,emmm.放了快一年了,悄悄放到博客里面. 功能需求在另一篇博客里 <?php function cny ...