内连接:
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. 水题系列二:PhoneNumbers

    问题描述: Phonenumbers 企业喜欢用容易被记住的电话号码.让电话号码容易被记住的一个办法是将它写成一 个容易记 住的 单词或 者短语 .例如 ,你 需要给 滑铁卢 大学打 电话时 ,可 以 ...

  2. 一、集合框架(Collection和Collections的区别)

    一.Collection和Map 是一个接口 Collection是Set,List,Queue,Deque的接口 Set:无序集合,List:链表,Queue:先进先出队列,Deque:双向链表 C ...

  3. Physical Limits of ASM

    Oracle version 7, only 1,022 datafiles per database could be used.  Oracle version 11g, support 65,5 ...

  4. 【转】借助System.Linq.Dynamic, IQueryable根据排序字符串排序

    在使用Entity Framework时,若有多个排序,需要OrderBy (OrderByDescending)再ThenBy (ThenByDescending) 假设需要根据Name升序排序,再 ...

  5. Python线程二

    转自:https://www.cnblogs.com/chengd/articles/7770898.html 1. threading.Lock() import threading balance ...

  6. python删除指定路径的文件

    import os            import glob                        path =imgDate_listResult            for infi ...

  7. Redis在linux环境下的安装和部署

    官网:http://redis.io          windows版本下载地址https://github.com/MicrosoftArchive/redis/releases 1Redis建议 ...

  8. js string对象方法

    substr(start,length) substring(start,end) 返回子串,原字符串不改变.

  9. windows中mysql5.7保存emoji表情

    1.找到my.ini文件,修改一下配置: [client] default-character-set=utf8mb4 [mysqld] character-set-client-handshake ...

  10. 蓝桥杯—BASIC-21 sine之舞(递归递推)

    题目:最近FJ为他的奶牛们开设了数学分析课,FJ知道若要学好这门课,必须有一个好的三角函数,所以他准备和奶牛们做一个“Sine之舞”的游戏,寓教于乐,提高奶牛们的计算能力. 不妨设 An=sin(1– ...