SQL SERVER CROSS repeated deduplication

       SQL SERVER inside deduplication is a frequently-used function, generally use the DISTINCT keyword to achieve, but only to heavy DISTINCT exact same content, if there are two fields, cross-repeated de-emphasis, it also requires special handling, method as follows:

--测试数据
if not object_id(N'Tempdb..#T') is null
    drop table #T
Go
Create table #T([字段A] nvarchar(23),[字段B] nvarchar(23))
Insert #T
select N'数据A',N'数据B' union all
select N'数据B',N'数据A' union all
select N'数据C',N'数据D'
Go
--测试数据结束
SELECT * FROM #T T1
WHERE NOT EXISTS(SELECT 1 FROM #T T2 WHERE T1.字段A=T2.字段B
    AND T1.字段B=T2.字段A AND T1.字段A>T2.字段A)

       . The key field where T1 is A> T2 field A, the following results:

Published 109 original articles · won praise 42 · views 570 000 +

Guess you like

Origin blog.csdn.net/sinat_28984567/article/details/98059951