SQL 服务器重复,XY、YX 重复的结果
SQL server duplicates, results with XY, YX duplicates
我 table 包含一些公司的信息。 table 包含此列。
Connectionkey|Phonenumber|Lastname|Firstname|Categoryid1|housenumber|Streettype|Street|Zipcode|Locality|Createts|lastuserid
我正在尝试根据某些列提取重复行
SELECT
Dup.Connectionkey,
Dup.Phonenumber,
Dup.Lastname,
Dup.Firstname,
Dup.Categoryid1,
Dup.housenumber,
Dup.Streettype,
Dup.Street,
Dup.Zipcode,
Dup.Locality,
Dup.Createts,
Dup.lastuserid,
Dup1.connectionkey,
Dup1.Phonenumber,
Dup1.Lastname,
Dup1.Firstname,
Dup1.Categoryid1,
Dup1.housenumber,
Dup1.Streettype,
Dup1.Street,
Dup1.Zipcode,
Dup1.Locality,
Dup1.Createts,
Dup1.lastuserid
From
spp Dup, spp Dup1
Where
Dup.supplierid in (4,6,7,9,11,16,48,49,50,51,52,53,54,55,56,61,62,63,65,66,67,68,70,74,77,78,79,80,87,84)
And
Dup1.supplierid in (4,6,7,9,11,16,48,49,50,51,52,53,54,55,56,61,62,63,65,66,67,68,70,74,77,78,79,80,87,84)
And
Dup.supplierid <> Dup1.supplierid
And
Dup.phonenumber=Dup1.phonenumber
And
Dup.zipcode=Dup1.zipcode
And
Dup.Locality=Dup1.Locality
And
(
Dup.street like '%'+Dup1.street+ '%'
Or
Dup1.street like '%'+Dup.street+ '%'
)
And
(
Dup.lastname like '%'+Dup1.lastname+ '%'
Or
Dup1.lastname like '%'+Dup.lastname+ '%'
)
我在查询中遇到的问题是,"Dup" 的结果数据在 "Dup2" 中重复。
所以在结果中我有 XY 和 YX。是一样的
我的问题是:如何避免这种重复,我使用了 DISTINCT 但它没有用。
您想改变...
Dup.supplierid <> Dup1.supplierid
到...
Dup.supplierid < Dup1.supplierid
现在每对你只会得到一次!
我 table 包含一些公司的信息。 table 包含此列。
Connectionkey|Phonenumber|Lastname|Firstname|Categoryid1|housenumber|Streettype|Street|Zipcode|Locality|Createts|lastuserid
我正在尝试根据某些列提取重复行
SELECT
Dup.Connectionkey,
Dup.Phonenumber,
Dup.Lastname,
Dup.Firstname,
Dup.Categoryid1,
Dup.housenumber,
Dup.Streettype,
Dup.Street,
Dup.Zipcode,
Dup.Locality,
Dup.Createts,
Dup.lastuserid,
Dup1.connectionkey,
Dup1.Phonenumber,
Dup1.Lastname,
Dup1.Firstname,
Dup1.Categoryid1,
Dup1.housenumber,
Dup1.Streettype,
Dup1.Street,
Dup1.Zipcode,
Dup1.Locality,
Dup1.Createts,
Dup1.lastuserid
From
spp Dup, spp Dup1
Where
Dup.supplierid in (4,6,7,9,11,16,48,49,50,51,52,53,54,55,56,61,62,63,65,66,67,68,70,74,77,78,79,80,87,84)
And
Dup1.supplierid in (4,6,7,9,11,16,48,49,50,51,52,53,54,55,56,61,62,63,65,66,67,68,70,74,77,78,79,80,87,84)
And
Dup.supplierid <> Dup1.supplierid
And
Dup.phonenumber=Dup1.phonenumber
And
Dup.zipcode=Dup1.zipcode
And
Dup.Locality=Dup1.Locality
And
(
Dup.street like '%'+Dup1.street+ '%'
Or
Dup1.street like '%'+Dup.street+ '%'
)
And
(
Dup.lastname like '%'+Dup1.lastname+ '%'
Or
Dup1.lastname like '%'+Dup.lastname+ '%'
)
我在查询中遇到的问题是,"Dup" 的结果数据在 "Dup2" 中重复。 所以在结果中我有 XY 和 YX。是一样的
我的问题是:如何避免这种重复,我使用了 DISTINCT 但它没有用。
您想改变...
Dup.supplierid <> Dup1.supplierid
到...
Dup.supplierid < Dup1.supplierid
现在每对你只会得到一次!