You didn't define "matching record" but assuming it means for each readcode display only one name and Turnkey.Try this:create table #junk (readcode int, name varchar(30), termkey varchar(30))insert #junkselect 0, 'Occupations', 'OCCUPATION' union allselect 2, 'Examination/Signs', 'SIGNS' union allselect 3, 'Diagnostic procedures', 'DIAGNOSTIC' union allselect 3, 'Diagnostic procedures', 'PROCEDURES'select readcode ,name ,termkeyfrom #junk awhere name + termkey in ( select top 1 name + termkey from #junk b where readcode = a.readcode order by name+termkey )drop table #junkOutput:readcode name termkey ----------- ------------------------------ ------------------------------ 0 Occupations OCCUPATION2 Examination/Signs SIGNS3 Diagnostic procedures DIAGNOSTIC
Be One with the OptimizerTG