Relationship Duplicate detection rule

I decided to add this forum to keep track of solutions for DB related problems.
I have worked with some brilliant people in my life and the solutions to issues that are usually beyond something you can get at Jack in Box Jackson. They deserve historical marker. This is the historical marked on my map.
Pouzivej data base
Post Reply
hudatolah
Site Admin
Posts: 159
Joined: Thu Apr 04, 2013 8:10 pm
Are You a Headhunter?: Affirmative
Surfer?: Yes

Relationship Duplicate detection rule

Post by hudatolah » Wed Aug 06, 2025 10:22 am

WITH RankedMatches AS (
SELECT reconciliationidentity,to_timestamp(createdate)as "Created Date", submitter,
markasdeleted,
Source_ReconciliationIdentity,Destination_ReconciliationIden,
datasetid,
classid, instanceid,
COUNT(*) OVER (PARTITION BY reconciliationidentity,Source_ReconciliationIdentity,Destination_ReconciliationIden, datasetid, classid) as total_count,
ROW_NUMBER() OVER (PARTITION BY Source_ReconciliationIdentity,Destination_ReconciliationIden, datasetid, classid, markasdeleted ORDER BY classid DESC) as rn
FROM BMC_CORE_BMC_BaseRelationship
WHERE datasetid = 'BMC.ASSET'
)
SELECT *
FROM RankedMatches
WHERE total_count >= 2 AND rn >= 2 --and source_reconciliationidentity != '0' and destination_reconciliationiden != '0'
and markasdeleted = '1'
--and reconciliationidentity = '0'
order by total_count DESC
The Blackholesurfer. My surfboard has teeth.