-- This is only going to work if there is only 1 head per unitnodeclare @employee table (EMPNO int, EMPNAME varchar(50), UNITNO int, JOBCODE int, LEVL varchar(10) )insert into @employeeselect 1111, 'Briggs', 2110, 1110, 'Head' union allselect 1112, 'Walter', 2110, 1120, 'empl' union allselect 1113, 'O''Sullivan', 2110, 1120, 'empl' union allselect 1114, 'Fred', 2120, 1110, 'Head' union allselect 1115, 'Paul', 2120, 1120, 'empl' union allselect 1116, 'John', 2120, 1120, 'empl'select a.EMPNAME as head, b.EMPNAME as employee from ( select * from @employee where Levl = 'Head' ) a left join ( select * from @employee where Levl = 'empl' ) b ON a.UNITNO = b.UNITNO
"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking