w3resource

SQL Exercise: Find the details of highest paid employee

SQL subqueries on employee Database: Exercise-18 with Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

18. From the following table, write a SQL query to find the highest paid employee. Return complete information about the employees.

Sample table: employees


Sample Solution:

SELECT *
FROM employees
WHERE salary IN
    (SELECT max(salary)
     FROM employees);

Sample Output:

 emp_id | emp_name | job_name  | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+-----------+------------+------------+---------+------------+--------
  68319 | KAYLING  | PRESIDENT |            | 1991-11-18 | 6000.00 |            |   1001
(1 row)

Explanation:

The said query in SQL that selects all information about employees whose salary is equal to the highest salary in the employees table.

The subquery in the WHERE clause that selects the maximum salary from the employees table. This subquery is then filters only the rows where the salary is equal to the maximum salary.

Practice Online


Structure of employee Database:

employee database structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: List any job of department ID 1001 not in ID 2001.
Next SQL Exercise: List jobs of department ID 1001, not found in ID 2001.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.