内部联接返回大量重复项 [英] Inner join returning large numbers of duplicates
本文介绍了内部联接返回大量重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下查询将两个表连接在一起:
I am using the following query to join two tables together:
SELECT SDA.smachIPAddress,
DPP.ScanName,
DPP.pspplMSSeverity,
DPP.PatchMissing,
DPP.ScanDate
FROM patchtest_withsev DPP
INNER JOIN patchtest_withip SDA
ON DPP.ScanName =SDA.ScanName
并接收2351行数据
当我查询patchtest_withsev表的所有记录时,它仅返回99,而patchtest_withip表仅返回99.
When I query the patchtest_withsev table for all records it only returns 99 and the patchtest_withip table only returns 99.
谁能看到为什么这个查询产生如此大的不匹配?
Can anyone see why this query is producing such a large mismatch?
推荐答案
似乎两个表都有几行,且每行具有相同的ScanName
值.
It seems that both table have several rows with same values of ScanName
.
例如:
table1:
f1 | f2
1 | a
1 | b
2 | c
2 | c
table2:
f1 | f2
1 | a
1 | b
2 | c
table1 INNER JOIN table2 ON table1.f1 = table2.f1给出:
table1 INNER JOIN table2 ON table1.f1 = table2.f1 gives:
table1.f1 | table1.f2 | table2.f1 | table2.f2
1 | a | 1 | a
1 | a | 1 | b
1 | b | 1 | a
1 | b | 1 | b
2 | c | 2 | c
2 | c | 2 | c
为避免结果中出现完全重复的行,请尝试使用DISTINCT
.
To avoid completely duplicate rows in result try using DISTINCT
.
这篇关于内部联接返回大量重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文