sql横着连接起来sql

SQL Join是什么意思? (What does a SQL Join mean?)

A SQL join describes the process of merging rows in two different tables or files together.

SQL连接描述了将两个不同表或文件中的行合并在一起的过程。

Rows of data are combined based on values in a selected column.

根据选定列中的值组合数据行。

In the example above, this is the Item column.

在上面的示例中,这是“ 项目”列。

An Item, Apple, has both a price and a quantity, but in different tables.

一个我TEM,苹果,既有价格和数量,但在不同的表。

Using a SQL join, these values become merged into one row!

使用SQL连接,这些值将合并为一行!

那么,为什么需要有关此内容的整篇文章? (So why do I need an entire article about this?)

In most cases, joining data won’t be as simple as the previous example. Oftentimes, we’ll have rows that can’t be joined because there isn’t the same value in the joining column for both tables.

在大多数情况下,合并数据不会像前面的示例那样简单。 通常,我们会有无法连接的行,因为两个表的连接列中的值都不相同。

For instance, what if there wasn’t a quantity for apple in the example above? How we handle what we do with rows like this depends on the type of SQL Join we choose.

例如,如果上面的示例中没有苹果数量,该怎么办? 处理此类行的方式取决于我们选择SQL Join的类型。

There are four main types of joins: inner join, left join, right join, and full join. In this article, I’ll explain to you what each type entails.

联接主要有四种类型:内部联接,左联接,右联接和完全联接。 在本文中,我将向您解释每种类型的含义。

Before going into everything, I think it’d be nice to mention that our tool Merge Spreadsheets is an easy to use tool that will easily perform all of this joining for you.

在介绍所有内容之前,我想很高兴地提到我们的工具“ 合并电子表格”是易于使用的工具,可以轻松地为您执行所有这些连接。

You can experiment with your spreadsheets to learn how these joins will look.

您可以尝试使用电子表格来了解这些联接的外观。

什么是内部联接? (What is an inner join?)

An inner join results in a table with rows where the values in the joining column are in both tables.

内部联接生成的表中具有行,其中联接列中的值都在两个表中。

To better understand this, let’s take a look at this example being joined on the item column:

为了更好地理解这一点,让我们看一下在item列上加入的示例:

Both of the starting tables have a lot of different items, but only Apple and Orange are in both. So, the final result will only include Apple and Orange with their price and quantity values merged into the same row.

两个起始表都有很多不同的项目,但是只有Apple和Orange都在。 因此,最终结果将仅包括将价格和数量值合并到同一行的Apple和Orange。

什么是左联接? (What is a left join?)

A left join will include all of the rows in the left table (file one), regardless of if they’re in the right table.

左联接将包括表(文件一)中的所有行,无论它们是否在右表中。

Let’s take a look at the same tables as before, also being merged on the item column:

让我们看一下与以前相同的表,它们也被合并在item列上:

Like with inner join, the final product of this join includes Apple and Orange. However, it also includes all the other rows from file one, even if they don’t have quantity values (those cells will be left blank)!

与内部联接一样,此联接的最终产品包括Apple和Orange。 但是,它也包括文件一中的所有其他行,即使它们没有数量值(这些单元格将留为空白)!

什么是正确的联接? (What is a right join?)

A right join is the exact opposite of a left join; it includes all the values in the right table (file two) regardless of what’s in the first table.

右连接与左连接完全相反; 它包括表(文件2)中的所有值,而不管第一个表中的内容如何。

So, in the same example as before, this will include Apple and Orange while also including any other rows in file two!

因此,在与之前相同的示例中,这将包括Apple和Orange,同时还包括文件2中的任何其他行!

什么是完全加入? (What is a full join?)

A full join will combine all the data from both spreadsheets while merging the rows that can be merged.

完全联接将合并两个电子表格中的所有数据,同时合并可以合并的行。

Full join is definitely the way to go if you don’t want to exclude any data in your final result.

如果您不想在最终结果中排除任何数据,完全连接绝对是正确的选择。

As always, using the same two tables as before will yield a different result when using a full join.

与往常一样,使用完全连接时,使用与以前相同的两个表将产生不同的结果。

All the rows from both tables are included and Apple and Orange become merged (as those are the only common items)!

两个表中的所有行都包括在内,Apple和Orange合并(因为这是唯一的常见项目)!

有趣的是,这会变得更加复杂吗? (Interesting, so does this get more complicated?)

It gets a little more complicated. There are a couple special cases that I’ll go into so that you’ll have a better understanding of how joining works!

它变得有点复杂。 我将介绍几种特殊情况,以便您对加入的工作方式有更好的了解!

如果我的数据重复了怎么办? (What if I have duplicates in my data?)

If you have duplicates in one table, they’ll also show up in your joined table depending on the join type.

如果您在一个表中有重复项,则它们还将显示在联接表中,具体取决于联接类型。

If there is a single row in one file with the same value in the joining column as multiple rows in the second file, those data in that single row will be repeated for each instance.

如果一个文件中的单行与第二个文件中的多行在连接列中具有相同的值,则将针对每个实例重复该单行中的那些数据。

For example, let’s look at the tables below being Inner joined on the Item column. In file one, there are two Orange rows while there’s only one in file two.

例如,让我们看一下在“ 项目”列上内部连接的下表。 在文件一中,有两个橙色行,而在文件二中只有一个。

Joining this will include both of the unique rows from file one while repeating the data for quantity from file two!

加入此文件将包括文件1的两个唯一行,同时重复文件2的数量数据!

By the way, a LEFT join would also produce the same result

顺便说一句, LEFT连接也会产生相同的结果

我可以共同加入多个列吗? (Can I join with multiple columns in common?)

Yes! If you want to join a table based on multiple columns, each grouping will be classified as its own unique entity.

是! 如果要基于多个列联接表,则每个分组都将分类为自己的唯一实体。

For instance, in the example below, we’ll be Full joining on the Item and Price columns.

例如,在下面的示例中,我们将在“ 项目”和“ 价格”列上进行“ 完全连接”。

The Apple row is the only one that’s merged because it’s the only one with the same Item and Price in both tables.

苹果行是唯一被合并的行,因为它是两个表中唯一具有相同项目价格的行

Instead of both of the Orange rows being merged, they are treated as different rows because their price values are different.

由于它们的价格值不同,因此不会将两个橙色行都合并,而是将它们视为不同的行。

So, everything is the same as before but now we look for the same values in two columns rather than just one.

因此,一切都与以前相同,但是现在我们在两列中寻找相同的值,而不仅仅是一列。

如果我的公用栏中有空白值怎么办? (What if I have a blank value in my common column?)

Each blank value in the column you’re joining on will be treated like any normal value. In other words, you can join on a blank value as usual.

您要加入的列中的每个空白值都将被视为任何常规值。 换句话说,您可以照常加入空白值。

For example, in the tables above, there are blank values in both files in the item column. These will be treated as the same string and become joined! In the case of the example above, all types of joining will result in the same product.

例如,在上表中,项目列中的两个文件都有空白值。 这些将被视为相同的字符串并加入! 在上面的示例中,所有类型的连接都将产生相同的产品。

NOTE: While a blank value will be treated as any other string, a NULL value is different. NULL values denote nothing and are typically used in code. Each NULL value is treated as a unique entity and can’t be joined on. For more information, check out this article.

Let’s also take a look at a more comprehensive example with all of these special cases in it.

让我们也看看其中包含所有这些特殊情况的更全面的示例。

We will be performing a Left join on the Item and Price columns.

我们将在项目价格列上执行连接。

When performing a left join, all the rows from the left file will be in the final product.

执行联接时,左文件中的所有行都将在最终产品中。

The Apple,$1 row is in both files, so the ID# and quantity for them will be merge.

Apple,$ 1行在两个文件中,因此它们的ID#和数量将合并。

Orange,$2 is only in the left file, so its quantity will remain blank.

橙色,$ 2仅在左侧文件中,因此其数量将保持空白。

Finally, we have a blank/blank row in the left file and two blank/blank rows in the second file. This means the the ID # for blank/blank in file one will be repeated twice to go with each quantity value in the second table!

最后,左侧文件中有一个空白行,第二个文件中有两个空白行。 这意味着文件1中空白/空白的ID#将重复两次,以与第二张表中的每个数量值对应!

And the fully blank row at the bottom will be ignored!

底部的空白行将被忽略!

所以...我们涵盖了所有内容吗? (So… have we covered everything?)

Yep! We just went over all the basics of SQL joins so you should be able to join tables with no problems now.

是的 我们仅介绍了SQL连接的所有基础知识,因此您现在应该可以毫无问题地连接表。

Feel free to experiment with your data in spreadsheets at Merge Spreadsheets because there is nothing like trying this out to really understand it.

可以在Merge Spreadsheets的电子表格中随意尝试数据,因为没有什么可以像尝试这种方法那样真正理解它了。

If you still have questions, don’t hesitate to reach out to info@lovespreadsheets.com!

如果您仍有疑问,请随时联系info@lovespreadsheets.com!

Want to learn more about how to Merge Spreadsheets? Check out our ultimate guide here!

想更多地了解如何合并电子表格? 在这里查看我们的最终指南!

翻译自: https://medium.com/@lovespreadsheets/a-brief-yet-comprehensive-introduction-to-sql-joins-de2fa412d2e

sql横着连接起来sql


http://www.taodudu.cc/news/show-994909.html

相关文章:

  • 如何击败Python的问题
  • 数据冒险控制冒险_劳动生产率和其他冒险
  • knn 邻居数量k的选取_选择K个最近的邻居
  • 什么样的代码是好代码_什么是好代码?
  • 在Python中使用Twitter Rest API批量搜索和下载推文
  • 大数据 vr csdn_VR中的数据可视化如何革命化科学
  • 导入数据库怎么导入_导入必要的库
  • 更便捷的画决策分支图的工具_做出更好决策的3个要素
  • 矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵
  • bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程
  • 脚本 api_从脚本到预测API
  • binary masks_Python中的Masks概念
  • python 仪表盘_如何使用Python刮除仪表板
  • aws emr 大数据分析_DataOps —使用AWS Lambda和Amazon EMR的全自动,低成本数据管道
  • 先进的NumPy数据科学
  • 统计和冰淇淋
  • 对数据仓库进行数据建模_确定是否可以对您的数据进行建模
  • python内置函数多少个_每个数据科学家都应该知道的10个Python内置函数
  • 针对数据科学家和数据工程师的4条SQL技巧
  • 芒果云接吗_芒果糯米饭是生产力的关键吗?
  • 公司生日会生日礼物_你的生日有多受欢迎?
  • 旧金山字体_旧金山建筑业的兴衰。 施工趋势与历史
  • lambda函数,函数符_为什么您永远不应该在Lambda函数中使用print()
  • ai 中 统计_AI统计(第2部分)
  • twitter数据分析_Twitter上最受欢迎的数据科学文章主题
  • 是什么使波西米亚狂想曲成为杰作-数据科学视角
  • 流行编程语言_编程语言的流行度排名
  • corba的兴衰_数据科学薪酬的兴衰
  • 通才与专家_那么您准备聘请数据科学家了吗? 通才还是专家?
  • 数据科学家 数据工程师_数据科学家实际上赚了多少钱?

sql横着连接起来sql_SQL联接的简要介绍(到目前为止)相关推荐

  1. sql横着连接起来sql_SQL联接

    sql横着连接起来sql SQL Join is used to fetch data from two or more tables, which is joined to appear as si ...

  2. sql隐式连接和显示链接_SQL Server中的嵌套循环联接–批处理排序和隐式排序

    sql隐式连接和显示链接 In SQL Server, it`s not always required to fully understand the internal structure, esp ...

  3. SQL中内连接、外连接、交叉连接

    SQL中内连接.外连接.交叉连接 SQL连接可以分为内连接.外连接.交叉连接. 数据库数据:            book表                                      ...

  4. SQL Server 2005 连接本地端口1433开启远程连接/登陆18456错误的解决方法

    SQL Server 2005 连接本地端口1433开启远程连接/登陆18456错误的解决方法 出处:http://jimmyli.blog.51cto.com/我站在巨人肩膀上Jimmy Li 作者 ...

  5. SQL 左外连接,右外连接,全连接,内连

    SQL 左外连接,右外连接,全连接,内连接       连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件.WHERE和HAVING子句也可以包含搜索条件,以进一步筛选连接条 ...

  6. SQL三种连接:内连接、外连接、交叉连接

    SQL三种连接:内连接.外连接.交叉连接 一.交叉连接(CROSS JOIN) 二.内连接(INNER JOIN) 三.外连接(LEFT JOIN.RIGHT JOIN.FULL JOIN) 1.左外 ...

  7. SQL 左外连接,右外连接,全连接,内连接带图详细介绍

    SELECT id, name,description,img_url,sort,is_display ​ from bbs_brand ORDER BY id DESC ​ limit startR ...

  8. SQL Server 表连接

    目录 SQL Server 内连接 SQL Server 左连接 ON与WHERE子句 SQL Server 右连接 SQL Server 交叉连接 SQL Server自连接 SQL Server全 ...

  9. 左右链接php,sql的左连接和右连接有什么区别

    sql的左连接和右连接区别:1.左连接只要左边表中有记录,数据就能检索出来,而右连接是只要右边表中有记录:2.左连接是已左边表中的数据为基准,而右联接是左向外联接的反向联接. 本文操作环境:Windo ...

最新文章

  1. VS2010 运行速度加快方法
  2. 程序员成功之路 ——The road ahead for programmer(转引)
  3. ajax.filter json过滤,$.ajax()的dataFilter方法
  4. 花 1 个月收入购买一份保险之后,我的一点碎碎念!
  5. python冒泡排序代码完整_用Python写冒泡排序代码
  6. [Spring5]Spring框架概述
  7. jsf绑定bean_JSF –渴望的CDI bean
  8. 互联网寒冬!“996”为什么还没实行?我还等着早点下班呢!
  9. 微信小程序点播插件_微信小程序 wxParse插件显示视频问题
  10. JavaScript中的(字符串,数字型,布尔型)是如何实现类型转换的?
  11. mysql -f --force_MySQL force Index 强制索引概述
  12. 计算机农业sci,科学网—SCI-EI收录农业工程期刊 - 王宝济的博文
  13. main()的使用说明 (一叶知秋)
  14. 计算机编程 计算存款利息,作业报告12 定期存款利息计算器
  15. 码农饭碗不保——ChatGPT正在取代Coder
  16. i78700k配什么显卡好_八代i7 8700配什么显卡好?intel酷睿i7-8700适合搭配的显卡推荐...
  17. 全志R16_SPI总线驱动的使用文档,全志R16开发资料
  18. 【环境安装】ubuntu18.04利用opam安装指定版本的coq工作环境
  19. 高数 李永乐 第一章
  20. android 摄像头 蓝条,微信小程序拍照部分Android机出现蓝色精灵人现象

热门文章

  1. pic单片机c语言读eeprom,PIC16F877单片机内部EEPROM读写实例
  2. 排序(基本概念及分类,直接插入排序和希尔排序)
  3. H.264中IDR帧和I帧区别
  4. 深入理解linux系统下proc文件系统内容
  5. C++ 写时拷贝 2
  6. 7年老Android一次操蛋的面试经历,系列教学
  7. 【微信小程序】java最简单观察者模式
  8. 阿里P8亲自讲解!javawhile循环语句用法
  9. vue实现可编辑的文字_苹果还自带文字转语音,只要一键按下便可实现,今天分享给大家...
  10. [Objective-C语言教程]结构体(17)