The best I could come up with is iteration:-- *** Test Data ***-- Please supply in consumable formatCREATE TABLE #t( ID int NOT NULL ,Dept int NOT NULL ,[Address] varchar(30) NOT NULL ,GroupID int NOT NULL ,NewGroupID int NULL)INSERT INTO #t (ID, Dept, [Address], GroupID)VALUES (165683, 32, 'PO BOX 602', 2),(165925, 32, 'PO BOX 562', 2),(165696, 50, 'PO BOX 602', 4) ,(164356, 103, 'PO BOX 175', 6),(164356, 103, 'PO BOX 175', 6),(164368, 203, 'PO BOX 72', 19) ,(165856, 264, 'PO BOX 562', 27),(164374, 302, 'PO BOX 39', 32),(164375, 303, 'PO BOX 368', 33) ,(164375, 303, 'PO BOX 368', 33),(164375, 303, 'PO BOX 368', 33),(164375, 303, 'PO BOX 368', 33) ,(165934, 303, 'PO BOX 175', 33),(165934, 303, 'PO BOX 175', 33),(164382, 406, 'PO BOX 72', 47) ,(164421, 905, 'PO BOX 39', 57),(165616, 4310, 'PO BOX 368', 87),(165616, 4310, 'PO BOX 368', 87) ,(165616, 4310, 'PO BOX 368', 87),(165616, 4310, 'PO BOX 368', 87),(166077, 4913, 'ROUTE 3', 89) ,(165768, 5434, 'PO BOX 368', 91),(164905, 5434, 'PO BOX 368', 91),(165768, 5434, 'PO BOX 368', 91) ,(164905, 5434, 'PO BOX 368', 91),(165768, 5434, 'PO BOX 368', 91),(164905, 5434, 'PO BOX 368', 91) ,(164934, 5803, 'PO BOX 368', 92),(164934, 5803, 'PO BOX 368', 92),(164934, 5803, 'PO BOX 368', 92) ,(164934, 5803, 'PO BOX 368', 92),(166095, 8040, 'ROUTE 3', 109),(165294, 9311, 'PO BOX 175', 115) ,(165294, 9311, 'PO BOX 175', 115);-- *** End Test Data ***WHILE 1=1BEGIN; WITH AddrGrps AS ( SELECT ID, Dept, [Address], GroupID, NewGroupID ,MIN(COALESCE(NewGroupID, GroupID)) OVER (PARTITION BY [Address]) AS MinGroupID FROM #t ) ,DeptGrps AS ( SELECT ID, Dept, [Address], GroupID, NewGroupID ,MIN(MinGroupID) OVER (PARTITION BY Dept) AS MinGroupID FROM AddrGrps ) UPDATE DeptGrps SET NewGroupID = MinGroupID WHERE NewGroupID IS NULL OR NewGroupID <> MinGroupID IF @@ROWCOUNT = 0 BREAK;END;select * from #t;