Posted by: YoTaBhayanaNiSom October 18, 2010
Login in to Rate this Post:
0
?
Stiffler's query is ok for 2 for the given data. But if there are multiple employees (whether in the same department or different departments) that earn the same salary that happen to be the highest for the company, then the query will return an error.
Following query should handle that situation.
Select fname, lname
From employee
Where dno in (select distinct dno from employee where salary=(select max(salary) from employee));
Or you could use this.
Select e.fname, e.lname
From employee e inner join
(select distinct dno from employee
where salary=(select max(salary) from employee)
) m
on e.dno = m.dno