Select Item,OPC,Code1,Code2,Value,Desc
from #tmp2 cwhere c.opc = (select max(d.opc) from #tmp2 d where c.opc = d.opc and c.items = d.items and c.code1 = d.code1 and c.code2 = d.code2 and c.value = d.value and c.desc = d.desc)Group by Item,OPC,Code1,Code2,Value,Desc
That is my solution I just forgot to include it.
The same wrong answer, I couldn't get the grouping that I was listed above.