【发布时间】:2022-01-05 09:38:48
【问题描述】:
直到今天我对内连接的想法是它将返回满足连接条件的表中存在的最小行数。
Ex. 如果 table A 包含 4 行,而 table B 包含 7 rows 。如果满足加入条件,我期望 4 行可以是最大输出。
我刚刚写了一个 sp,我在其中创建了两个临时表并填充它们。然后我对它们进行了内部连接,但返回了更多行(在我的情况下,返回了 29 行,我期待 4 行) 经过一番搜索,我发现了这个 link
这证实了我可以发生,但我仍然想知道我的选择是什么来限制返回的结果。
下面是我的存储过程。
ALTER PROCEDURE [dbo].[GetDDFDetailOnSiteCol]
@siteId int,
@colNum int
AS
BEGIN
SET NOCOUNT ON;
create Table #portDetail
(
ddfId int,
portDetail nvarchar(50),
siteId int
)
Insert into #portDetail SELECT ddf.id, ddf.portDetail, site.Site_ID from site
inner join ddf ON site.Site_ID = ddf.siteCodeID
where ddf.siteCodeID = @siteId and ddf.colNo= @colNum
order by colNo,blockNum,portRowNum,portColNum
create Table #portAllocationDetail
(
assigned_slot nvarchar(50),
siteId int
)
Insert into #portAllocationDetail
SELECT dbo.portList.assigned_slot, dbo.site.Site_ID
FROM dbo.portList INNER JOIN
dbo.site ON dbo.portList.siteCodeID = dbo.site.Site_ID
where dbo.site.Site_ID = @siteId
--select * from #portAllocationDetail
Select #portDetail.ddfId,#portDetail.portDetail,#portAllocationDetail.siteId,#portAllocationDetail.assigned_slot FROM #portDetail
INNER JOIN #portAllocationDetail
ON
#portDetail.siteId = #portAllocationDetail.siteId
END
【问题讨论】:
-
如何确定返回表 B 中的哪些行?
-
我写选择语句。一个仍然存在评论
标签: sql-server tsql