数据库

作者: YDDMAX_Y | 来源:发表于2019-11-13 10:06 被阅读0次

1.0 INSERT ON DUPLICATE KEY UPDATE

当插入的数据中的主键 与 数据库中现有的数据主键 重复的情况下就不会执行插入操作,而是可以对现有的数据进行更新操作,不存在相同主键则执行插入操作。

2.0 join

参见 https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

  1. INNER JOIN
  2. LEFT JOIN
  3. RIGHT JOIN
  4. OUTER JOIN
  5. LEFT JOIN EXCLUDING INNER JOIN
  6. RIGHT JOIN EXCLUDING INNER JOIN
  7. OUTER JOIN EXCLUDING INNER JOIN

For the sake of this article, I'll refer to 5, 6, and 7 as LEFT EXCLUDING JOIN, RIGHT EXCLUDING JOIN, and OUTER EXCLUDING JOIN, respectively. Some may argue that 5, 6, and 7 are not really joining the two tables, but for simplicity, I will still refer to these as Joins because you use a SQL Join in each of these queries (but exclude some records with a WHERE clause).

2.1 Inner JOIN

INNER_JOIN.png

This is the simplest, most understood Join and is the most common. This query will return all of the records in the left table (table A) that have a matching record in the right table (table B). This Join is written as follows:

2.2 Left JOIN

LEFT_JOIN.png

This query will return all of the records in the left table (table A) regardless if any of those records have a match in the right table (table B). It will also return any matching records from the right table. This Join is written as follows:

2.3 Right JOIN

RIGHT_JOIN.png

This query will return all of the records in the right table (table B) regardless if any of those records have a match in the left table (table A). It will also return any matching records from the left table. This Join is written as follows:

2.4 Outer JOIN

FULL_OUTER_JOIN.png

This Join can also be referred to as a FULL OUTER JOIN or a FULL JOIN. This query will return all of the records from both tables, joining records from the left table (table A) that match records from the right table (table B). This Join is written as follows:

2.5 Left Excluding JOIN

LEFT_EXCLUDING_JOIN.png

This query will return all of the records in the left table (table A) that do not match any records in the right table (table B). This Join is written as follows:

2.6 Right Excluding JOIN

RIGHT_EXCLUDING_JOIN.png

This query will return all of the records in the right table (table B) that do not match any records in the left table (table A). This Join is written as follows:

2.7 Outer Excluding JOIN

OUTER_EXCLUDING_JOIN.png

This query will return all of the records in the left table (table A) and all of the records in the right table (table B) that do not match. I have yet to have a need for using this type of Join, but all of the others, I use quite frequently. This Join is written as follows:

相关文章

  • MySQL数据库day01

    系统数据库 ​​​ 创建数据库 ​​​ ​​​ ​​​ ​​​ 查看所有数据库 使用数据库 修改数据库 删除数据库...

  • 数据库操作

    创建数据库: 选择数据库: 查看数据库: 修改数据库: 删除数据库:

  • Ubuntu操作mysql数据库命令

    一、连接数据库 连接本地数据库 退出数据库 二、操作数据库 创建数据库 显示数据库 删除数据库 连接数据库 查看状...

  • 4-14

    创建数据库 createdatabase数据库名称; 删除数据库 dropdatabase数据库名称; 查看数据库...

  • [后端开发] Mysql学习笔记

    1.0 数据库 创建数据库 查看所有数据库 删除数据库 切换数据库名 查看正在使用的数据库 2.0 数据库表 创...

  • 2020最新最全数据库系统安全

    数据库标识与鉴别 数据库访问控制 数据库安全审计 数据库备份与恢复 数据库加密 资源限制 数据库安全加固 数据库安...

  • 2020-01-05 sql基本概念

    数据库用来储存数据。 数据库的种类大致有:层次数据库、关系数据库、面向对象数据库、XML数据库、键值数据库。 关系...

  • Mysql数据库基本操作

    连接数据库 退出数据库 查看数据库版本 显示数据库时间 查看当前使用的数据库 查看所有数据库 数据库备份 导入数据...

  • mysql命令行操作

    准备 登陆 数据库操作 查看现有数据库 创建数据库 删除数据库 查看数据库 使用数据库 查看当前数据库 表操作 新...

  • 1.7.1 MySQL数据库学习

    1. 数据库命令行学习 进入数据库 创建数据库 查看数据库列表 删除数据库 使用数据库 查看当前数据库 2. 表 ...

网友评论

      本文标题:数据库

      本文链接:https://www.haomeiwen.com/subject/fofhictx.html