SQL INNER JOIN
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 |
SQL INNER JOIN的更多相关文章
- 图解SQL的Join 转自coolshell
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...
- 图解SQL的Join(转)
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...
- SQL JOIN\SQL INNER JOIN 关键字\SQL LEFT JOIN 关键字\SQL RIGHT JOIN 关键字\SQL FULL JOIN 关键字
SQL join 用于根据两个或多个表中的列之间的关系,从这些表中查询数据. Join 和 Key 有时为了得到完整的结果,我们需要从两个或更多的表中获取结果.我们就需要执行 join. 数据库中的表 ...
- 关于sql中join
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...
- 图解SQL的Join(转摘)
转摘网址:http://coolshell.cn/articles/3463.html 对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的 ...
- SQL RIGHT JOIN 关键字
SQL RIGHT JOIN 关键字 RIGHT JOIN 关键字会右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行. RIGHT JOIN ...
- SQL LEFT JOIN 关键字
SQL LEFT JOIN 关键字 LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行. LEFT JOIN 关键 ...
- SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)
SQL 连接 JOIN 例解.(左连接,右连接,全连接,内连接,交叉连接,自连接) 最近公司在招人,同事问了几个自认为数据库可以的应聘者关于库连接的问题,回答不尽理想-现在在这写写关于它们的作用假设有 ...
- SQL Server Join方式
原文:SQL Server Join方式 0.参考文献 Microsoft SQL Server企业级平台管理实践 看懂SqlServer查询计划 1.测试数据准备 参考:Sql Server中的表访 ...
- SQL的JOIN语法解析(inner join, left join, right join, full outer join的区别)
原文链接:http://www.powerxing.com/sql-join/ 总的来说,四种JOIN的使用/区别可以描述为: left join 会从左表(shop)那里返回所有的记录,即使在右表( ...
随机推荐
- mp4文件数据格式解析
unsigned int(32)[3] 32*3bit string[32] 32*8bit class VisualSampleEntry(codingname) extends Sampl ...
- ref:PHP反序列化漏洞成因及漏洞挖掘技巧与案例
ref:https://www.anquanke.com/post/id/84922 PHP反序列化漏洞成因及漏洞挖掘技巧与案例 一.序列化和反序列化 序列化和反序列化的目的是使得程序间传输对象会更加 ...
- BNUOJ 52517 Another Server
网络流. 似乎有别的做法,没想. #include<bits/stdc++.h> using namespace std; + ; const int INF = 0x7FFFFFFF; ...
- POJ3255 Roadblocks [Dijkstra,次短路]
题目传送门 Roadblocks Description Bessie has moved to a small farm and sometimes enjoys returning to visi ...
- 【BZOJ 4035】 4035: [HAOI2015]数组游戏 (博弈)
4035: [HAOI2015]数组游戏 Time Limit: 15 Sec Memory Limit: 32 MBSubmit: 181 Solved: 89 Description 有一个长 ...
- 【51Nod 1815】【算法马拉松 23】调查任务
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1815 tarjan缩点后在DAG上递推即可. 每个点维护所有根到它的路径 ...
- bzoj4556: [Tjoi2016&Heoi2016]字符串 (后缀数组加主席树)
题目是给出一个字符串,每次询问一个区间[a,b]中所有的子串和另一个区间[c,d]的lcp最大值,首先求出后缀数组,对于lcp的最大值肯定是rank[c]的前驱和后继,但是对于这个题会出现问题,就是题 ...
- 洛谷P4009 汽车加油行驶问题
题目描述 给定一个 N \times NN×N 的方形网格,设其左上角为起点◎,坐标(1,1)(1,1),XX 轴向右为正, YY 轴向下为正,每个方格边长为 11 ,如图所示. 一辆汽车从起点◎出发 ...
- uoj 66 新年的巧克力棒 数学
#66. 新年的巧克力棒 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/66 Description 马上就要 ...
- div中内容超出自动换行
下面以table中td的内容超出为例说明: 首先: td { display: block; } 然后:给td设置css样式: 1. td { word-wrap: break-word; } 2. ...