内连接:
mysql> select * from book_wangjing as book_1 inner join user_wangjing as user_1 on book_1.id=user_1.id limit 2;
+----+------------------------+-------------+-------+--------------+----+---------------------+------------+---------------------+----------+
| id | book_name              | book_author | price | publish_date | id | date1               | date2      | date3               | time     |
+----+------------------------+-------------+-------+--------------+----+---------------------+------------+---------------------+----------+
|  1 | webdriver 框架实战指南 | 吴老师      |   100 | 2018-05-05   |  1 | 2018-05-05 00:08:24 | 2018-05-05 | 2018-05-05 00:08:24 | 00:08:24 |
|  2 | how google test        | 李老师      |    99 | 2018-05-05   |  2 | 2018-05-05 00:08:54 | 2018-05-05 | 2018-05-05 00:08:54 | 00:08:54 |
+----+------------------------+-------------+-------+--------------+----+---------------------+------------+---------------------+----------+
2 rows in set (0.00 sec)
 
左连接:
mysql> select a.* from author_wangjing as a left join book_wangjing as b on a.author_name=b.book_author;
+----+-------------+--------+
| id | author_name | salary |
+----+-------------+--------+
|  1 | 吴老师      |  10000 |
|  3 | Mr Jackson  |  15000 |
|  2 | 张老师      |  13000 |
+----+-------------+--------+
3 rows in set (0.07 sec)
 
右连接:
mysql> select * from user_wangjing as user_1 right join book_wangjing as book_1 on user_1.id=book_1.id;
+------+---------------------+------------+---------------------+----------+----+------------------------+-------------+-------+--------------+
| id   | date1               | date2      | date3               | time     | id | book_name              | book_author | price | publish_date |
+------+---------------------+------------+---------------------+----------+----+------------------------+-------------+-------+--------------+
|    1 | 2018-05-05 00:08:24 | 2018-05-05 | 2018-05-05 00:08:24 | 00:08:24 |  1 | webdriver 框架实战指南 | 吴老师      |   100 | 2018-05-05   |
|    2 | 2018-05-05 00:08:54 | 2018-05-05 | 2018-05-05 00:08:54 | 00:08:54 |  2 | how google test        | 李老师      |    99 | 2018-05-05   |
|    3 | 2018-05-05 00:08:55 | 2018-05-05 | 2018-05-05 00:08:55 | 00:08:55 |  3 | unit test              | 李老师      |     1 | 2018-05-05   |
|    4 | 2018-05-05 00:08:56 | 2018-05-05 | 2018-05-05 00:08:56 | 00:08:56 |  4 | function test          | 李老师      |    10 | 2017-11-10   |
| NULL | NULL                | NULL       | NULL                | NULL     |  5 | function test          | Mr Jackson  |    10 | 2013-06-10   |
+------+---------------------+------------+---------------------+----------+----+------------------------+-------------+-------+--------------+
5 rows in set (0.07 sec)
 
mysql> select a.* from author_wangjing as a right join book_wangjing as b on a.author_name=b.book_author;
+------+-------------+--------+
| id   | author_name | salary |
+------+-------------+--------+
|    1 | 吴老师      |  10000 |
|    3 | Mr Jackson  |  15000 |
| NULL | NULL        |   NULL |
| NULL | NULL        |   NULL |
| NULL | NULL        |   NULL |
+------+-------------+--------+
 
union:
mysql> select book_author from book_wangjing union select author_name from author_wangjing;
+-------------+
| book_author |
+-------------+
| 吴老师      |
| 李老师      |
| Mr Jackson  |
| 张老师      |
+-------------+
4 rows in set (0.06 sec)
 

1、     内连接:结果集中出现的a.author_name和b.book_author必须同时在两个表存在

2、     左连接:结果集中出现的a.author_name必须在左表(author_wangjing表)存在且全部显示

3、     右连接:结果集中出现的b.book_author必须在右表(book_wangjing表)存在且全部显示

4、 union:做合并,使用union时左表的数据列要和右表的数据列一样多

【Python】sql-内连接,左连接,右连接,union的更多相关文章

  1. Python进阶----多表查询(内连,左连,右连), 子查询(in,带比较运算符)

    Python进阶----多表查询(内连,左连,右连), 子查询(in,带比较运算符) 一丶多表查询     多表连接查询的应用场景: ​         连接是关系数据库模型的主要特点,也是区别于其他 ...

  2. SQL-内连接、外连接(左、右)、交叉连接

    本文测试基于以下两个表,student(左) \ teacher(右),使用数据库MariaDB,图形化界面HeidiSQL. 连接查询的概念:根据两个表或多个表的列之间的关系,从这些表中查询数据,即 ...

  3. LINQ 内链接 左链接 右链接

    原文地址:http://blog.sina.com.cn/s/blog_46e9573c01014fx2.html 1.左连接: var LeftJoin = from emp in ListOfEm ...

  4. mysql 内连接 左连接 右连接 外连接

    mysql> desc student;+-------+-------------+------+-----+---------+-------+| Field | Type | Null | ...

  5. 左连接,右连接,内连接,Union

    数据库的三种常用连接解析: 官方解释: 1.left [outer] join(左外联接) 返回 包括左表中的所有记录和右表中联结字段相等的记录 2.right [outer] join(右外联接) ...

  6. MySQL中的内连接、左连接、右连接、全连接、交叉连接

    创建两个表(a_table.b_table),两个表的关联字段分别为:a_table.a_id和b_table.b_id CREATE TABLE a_table ( a_id int NOT NUL ...

  7. 图解MySQL 内连接、外连接、左连接、右连接、全连接

    用两个表(a_table.b_table),关联字段a_table.a_id和b_table.b_id来演示一下MySQL的内连接.外连接( 左(外)连接.右(外)连接.全(外)连接). MySQL版 ...

  8. MySQL 内连接、外连接、左连接、右连接、全连接……太多了

    用两个表(a_table.b_table),关联字段a_table.a_id和b_table.b_id来演示一下MySQL的内连接.外连接( 左(外)连接.右(外)连接.全(外)连接). 主题:内连接 ...

  9. mysql内连接(inner join 找两个表的交集)、左连接(left join 交集并且左表所有)、右连接(right join 交集并且右表所有)、全连接(mysql不支持)

    用两个表(a_table.b_table),关联字段a_table.a_id和b_table.b_id来演示一下MySQL的内连接.外连接( 左(外)连接.右(外)连接.全(外)连接). MySQL版 ...

  10. sql 内连接和外链接

    如表     -------------------------------------------------     table1 | table2 |     ----------------- ...

随机推荐

  1. 解决spring-boot启动异常Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

    第一种: 需要在主类头加上  @EnableAutoConfiguration 第二种: pom文件是否加了 <dependency> <groupId>org.mybatis ...

  2. Beta阶段——第5篇 Scrum 冲刺博客

    Beta阶段--第5篇 Scrum 冲刺博客 标签:软件工程 一.站立式会议照片 二.每个人的工作 (有work item 的ID) 昨日已完成的工作 人员 工作 林羽晴 完成了邮箱发送功能的测试,测 ...

  3. ActiveMQ consumer按顺序处理消息

    http://activemq.apache.org/exclusive-consumer.html producer发送消息是有先后顺序的,这种顺序保持到了broker中.如果希望消息按顺序被消费掉 ...

  4. suffix word ard ar arian arium atic ation atory ator out ~3

      1★ ard 不好的人   2★ ar ~的:~人物     1● arian ~人.物     2● arium 地点,场地   3●aster   不怎么样的人     1● ast ~人   ...

  5. 变量和基本类型——复合类型,const限定符,处理类型

    一.复合类型 复合类型是指基于其他类型定义的类型.C++语言有几种复合类型,包括引用和指针. 1.引用 引用并非对象,它只是为一个已存在的对象所起的另外一个名字. 除了以下2种情况,其他所有引用的类型 ...

  6. Java Web(九) JDBC及数据库连接池及DBCP,c3p0,dbutils的使用

    DBCP.C3P0.DBUtils的jar包和配置文件(百度云盘):点我下载 JDBC JDBC(Java 数据库连接,Java Database Connectify)是标准的Java访问数据库的A ...

  7. PAT-GPLT训练集 L2-001 紧急救援(最短路)

    PAT-GPLT训练集 L2-001 紧急救援 题目大意:求最短路的条数,最短路中的权重和的最大值和这条最短路的路线 分析:使用dijkstra算法求出最短路,并且对dijkstra算法进行变化,设起 ...

  8. MyEclipse常用设置和快捷键

    Java快捷键 1.注释快捷键 先敲/  再敲两个**     Enter 回车 2.system.out.println(); 常用设置 [子类继承父类] [编码字体设置] 删除当前行:ctrl+d ...

  9. Win10系列:VC++ Direct3D模板介绍3

    (4)Render函数 默认定义在CubeRenderer.cpp源文件中的Render函数用于绘制立体图形,此函数的实现代码如下所示: void CubeRenderer::Render() {   ...

  10. LeetCode 回溯法 别人的小结 八皇后 递归

    #include <iostream> #include <algorithm> #include <iterator> #include <vector&g ...