May be this...METHOD 1 :CREATE TABLE #temp(ID int,NAME VARCHAR(100),[GROUP] VARCHAR(100))INSERT INTO #temp(ID,NAME,[GROUP]) VALUES(1,'MIC','DEFAULT'),(1,'MIC','TERR'),(2,'JAMES','DEFAULT'),(3,'KIM','HOL')SELECT a.ID ,a.NAme ,a.[Group] FROM(SELECT * ,CASE WHEN COUNT(ID)OVER (PARTITIOn BY ID)>1 THEN (SELECT t2.[GROUP] FROM dbo.#temp t2 WHERE t.ID = t2.ID AND t2.[GROUP] !='Default') ELSE t.[GROUP] END AS 'GroupCheck'FROM dbo.#temp t) aWHERE a.[Group] =a.GroupCheckDROP TABLE dbo.#temp
METHOD 2:SELECT a.*FROM( SELECT * FROM #temp ) aLEFT JOIN( SELECT * FROM #temp t WHERE (t.[GROUP] != 'Default' AND ID IN (SELECT #temp.ID FROM #temp)) ) b ON a.ID = b.ID WHERE a.[GROUP] = b.[GROUP] OR b.[GROUP] IS NULL
---------------Murali KrishnaYou live only once ..If you do it right once is enough.......