内连接:
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. leetcode-algorithms-35 Search Insert Position

    leetcode-algorithms-35 Search Insert Position Given a sorted array and a target value, return the in ...

  2. bootstrap fileinput组件的使用

    组件的下载地址为:https://github.com/kartik-v/bootstrap-fileinput 比较详细的介绍可参看:http://www.jq22.com/jquery-info5 ...

  3. The type java.lang.Object cannot be resolved

    有时候在Eclipse中打开或者导入项目时会出现标题字样的问题:The type java.lang.Object cannot be resolved. It is indirectly refer ...

  4. ubuntu默认启动方式修改 psensor命令

    Check UUID sudo blkid Then sudo gedit /etc/default/grub & to pull up the boot loader configurati ...

  5. Ubuntu Windows双系统重装windows后看不到ubuntu启动引导

    1.下载并安装Easy BCD 2.点击编辑引导菜单,看到只有windows一项 3.点击“添加新条目”,添加引导菜单,选择linux/bsd ,类型选择GRUB 2,然后输入名称,选择Ubuntu所 ...

  6. CSS3 的box-shadow进阶之 - 基础知识篇

    box-shadow被认为是CSS3最好的特性之一,发挥想象力,搭配其它属性,可以做出很多好看的效果(如下图,将会放在下一篇文章讲解),这篇文章主要讲一下box-shadow的基础知识.       ...

  7. 【Jmeter基础知识】Jmeter响应断言和断言结果

    一.Jmeter创建一个响应断言 1.步骤:添加--断言--响应断,进入响应断言页面 2.断言内容:可以采用直接去搜索某些文本信息,或者可以去断言某个变量,如图 二.Jmeter创建一个断言结果 1. ...

  8. 每天CSS学习之border-spacing

    border-spacing是CSS2的一个属性.其作用是规定表格的相邻单元格边框之间的距离.如果表格的border-collapse属性值为collapse时,border-spacing设置无效. ...

  9. vue-13-插件

    Vue.js 的插件应当有一个公开方法 install MyPlugin.install = function (Vue, options) { // 1. 添加全局方法或属性 Vue.myGloba ...

  10. QuickHit 项目

    package cn.javaoppday01; import java.util.Random; public class Game { public Player player; public G ...