perhaps something like this:select d.departmentid ,d.departmentName ,case when count(e.employeeid) > 0 then 1 else 0 end as hasEmployeesfrom departments dleft outer join employees e on e.deptid = d.deptidgroup by d.departmentid ,d.departmentName
EDIT:This may be better as you can add as many department columns without needing a GROUP BY:select d.departmentid ,d.departmentName ,case when count(e.employeeid) > 0 then 1 else 0 end as hasEmployeesfrom department douter apply (select count(*) from employees where deptid = d.deptid) e
Be One with the OptimizerTG