Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PostgreSQL Subquery: Find the names and salaries of the employees who have higher salary than the employee whose last_name is Bull


1. Write a query to find the first_name, last_name and salaries of the employees who have a higher salary than the employee whose last_name is Bull.

Sample Solution:

Code:

SELECT first_name, last_name, salary 
FROM employees 
WHERE salary > 
(SELECT salary 
FROM employees 
WHERE last_name = 'Bull');

Sample table: employees


Output:

pg_exercises=# SELECT first_name, last_name, salary
pg_exercises-# FROM employees
pg_exercises-# WHERE salary >
pg_exercises-# (SELECT salary
pg_exercises(# FROM employees
pg_exercises(# WHERE last_name = 'Bull');
 first_name  | last_name  |  salary
-------------+------------+----------
 Alexander   | Hunold     |  9000.00
 Bruce       | Ernst      |  6000.00
 David       | Austin     |  4800.00
 Valli       | Pataballa  |  4800.00
 Diana       | Lorentz    |  4200.00
 Den         | Raphaely   | 11000.00
 Steven      | King       | 24000.00
 Neena       | Kochhar    | 17000.00
 Janette     | King       | 10000.00
 Patrick     | Sully      |  9500.00
 Allan       | McEwen     |  9000.00
 Lindsey     | Smith      |  8000.00
 Louise      | Doran      |  7500.00
 Sarath      | Sewall     |  7000.00
 Clara       | Vishney    | 10500.00
 Mattea      | Marvins    |  7200.00
 Payam       | Kaufling   |  7900.00
 Shanta      | Vollman    |  6500.00
 Kevin       | Mourgos    |  5800.00
 Ellen       | Abel       | 11000.00
 Alyssa      | Hutton     |  8800.00
 ...         | ...        |  ...
 Hermann     | Baer       | 10000.00
 Shelley     | Higgins    | 12000.00
 William     | Gietz      |  8300.00
(62 rows)

Practice Online


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

Previous: PostgreSQL Subquery - Exercises, Practice, Solution
Next: Write a SQL subquery to find the first_name and last_name of all employees who works in the IT department.

What is the difficulty level of this exercise?