博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL INNER JOIN
阅读量:6037 次
发布时间:2019-06-20

本文共 1435 字,大约阅读时间需要 4 分钟。

A INNER JOIN command is queries that combine data from more than 1 table.

For two tables that want to join together need to have some data in common, like unique id that link this 2 tables together.

INNER JOIN will need a joining condition or connecting column to display out the joined data. 1 joining condition needs when we want to join 2 tables. If more than 2 tables want to join together, more joining condition or connecting column needed.

A connecting column should have values that match easily for both tables. Connecting columns almost always have the same datatype. The value in the connecting columns are join compatible or can say that the value are come from the same general class of data.

SQL INNER JOIN syntax:

SELECT *FROM [TABLE 1] INNER JOIN [TABLE 2]

ON [TABLE 1].[COLUMN NAME 1] = [TABLE 2].[COLUMN NAME 2]

EXAMPLE :

Let’s say, we only want to join 2 tables below and display only PlayerName and DepartmentName

Table 1: GameScores

PlayerName DepartmentId Scores
Jason 1 3000
Irene 1 1500
Jane 2 1000
David 2 2500
Paul 3 2000
James 3 2000

Table 2: Departments

DepartmentId DepartmentName
1 IT
2 Marketing
3 HR

The joining Condition will be DepartmentId of both tables.

SQL statement :

SELECT PlayerName, DepartmentName

FROM GameScores2 INNER JOIN Departments
ON GameScores2.DepartmentId = Departments.DepartmentId

Result:

PlayerName DepartmentName
Jason IT
Irene IT
Jane Marketing
David Marketing
Paul HR
James HR

转载地址:http://nklhx.baihongyu.com/

你可能感兴趣的文章
云场景实践研究第24期:巧思科技
查看>>
Puppet自动化运维排错案例
查看>>
从玩具到游戏,另类的项目激励机制
查看>>
远程桌面服务没有正常退出导致的问题
查看>>
mysql数据库主从正常切换IP脚本
查看>>
31天速成重构
查看>>
Pandas duplicated and drop_duplicates:查找并去除重复项
查看>>
Ransac 与 最小二乘(LS, Least Squares)拟合直线的效果比较
查看>>
如何使用Proxy模式及Java内建的动态代理机制
查看>>
综合应用WPF/WCF/WF/LINQ之四十:实现一个简单的DataGrid之CheckBox已勾选的项的保存...
查看>>
federated存储引擎实现跨服务器的数据访问
查看>>
《从零开始学Swift》学习笔记(Day60)——Core Foundation框架
查看>>
Java设计模式圣经连载(01)-简单工厂模式
查看>>
分享与快乐-我的Linux情结
查看>>
Android应用程序组件Content Provider的启动过程源代码分析(1)
查看>>
Azure运维系列 6:使用自定义映像创建虚拟机
查看>>
puppet成长日记二 Package资源详细介绍及案例分析
查看>>
AE+C# 向axPageLayoutControl1添加图例
查看>>
Hive Streaming 追加 ORC 文件
查看>>
打开Apache自带的Web监视器
查看>>