SQL INNER JOIN

本文介绍了SQL中的INNER JOIN命令,该命令用于从两个或多个表中提取数据,这些表需要通过共同的数据字段(如唯一ID)连接在一起。文章还详细解释了连接条件的重要性,并通过实例演示了如何使用INNER JOIN语法来实现表的连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

PlayerNameDepartmentIdScores
Jason13000
Irene11500
Jane21000
David22500
Paul32000
James32000

Table 2: Departments

DepartmentIdDepartmentName
1IT
2Marketing
3HR

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:

PlayerNameDepartmentName
JasonIT
IreneIT
JaneMarketing
DavidMarketing
PaulHR
JamesHR
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值