In one of the interviews one person asked me below question
“Write a query to find out all employee in all departments which are having highest salary in that department with department name,employee name and his salary”
It means that there are 100 records in employee table and 10 records in department table.
So it needs to give me 10 records from query plus if there is no employee in any department it still needs to show that department name.
Thanks
This query gives you a list of departments, with that department’s highest paid salary, if exists, or null otherwise. In this case, selecting the employee names do not give you the right name and just return the first employee in the linked department!
See on SQL Fiddle
If you wish a list of departments with the highest salary and employee name:
See on SQL Fiddle