w3resource

SQL Exercise: List the employees whose salary is more than JONAS

SQL subqueries on employee Database: Exercise-7 with Solution

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

7. From the following table, write a SQL query to find those employees whose salary is more than the salary of JONAS. Return complete information about the employees.

Sample table: employees


Sample Solution:

SELECT *
FROM employees
WHERE salary >
    (SELECT salary
     FROM employees
     WHERE emp_name = 'JONAS');

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
  67858 | SCARLET  | ANALYST   |      65646 | 1997-04-19 | 3100.00 |            |   2001
  69062 | FRANK    | ANALYST   |      65646 | 1991-12-03 | 3100.00 |            |   2001
(3 rows)

Explanation:

The said query in SQL that selects all employees whose salary is greater than that of the employee named 'JONAS' from the 'employees' table.

The WHERE clause filters the results to only include rows where the salary is greater than the salary of the employee named 'JONAS' which is determined by a subquery.

The subquery, which selects the salary of the employee named 'JONAS' from the 'employees' table.

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: Search for all grade 4 and 5 as Analysts and Managers.
Next SQL Exercise: List the employees with the same designation as FRANK.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/sql-exercises/employee-database-exercise/sql-subqueries-exercise-employee-database-7.php