PostgreSQL Subquery: Find some information of the employees who draws a salary that is higher than the salary of all shipping clerks
11. Write a subquery to find the first_name, last_name, job_id and salary of the employees who draws a salary that is higher than the salary of all the Shipping Clerk (JOB_ID = 'SH_CLERK'). Sort the results on salary from the lowest to highest.
SELECT first_name,last_name, job_id, salary FROM employees WHERE salary > ALL (SELECT salary FROM employees WHERE job_id = 'SH_CLERK') ORDER BY salary ;
Sample table: employees
pg_exercises=# SELECT first_name,last_name, job_id, salary pg_exercises-# FROM employees pg_exercises-# WHERE salary > pg_exercises-# ALL (SELECT salary pg_exercises(# FROM employees pg_exercises(# WHERE job_id = 'SH_CLERK') pg_exercises-# ORDER BY salary ; first_name | last_name | job_id | salary -------------+------------+------------+---------- Jennifer | Whalen | AD_ASST | 4430.00 David | Austin | IT_PROG | 4830.00 Valli | Pataballa | IT_PROG | 4830.00 Kevin | Mourgos | Salesman | 5830.00 Bruce | Ernst | IT_PROG | 6030.00 Pat | Fay | MK_REP | 6030.00 Sundita | Kumar | SA_REP | 6130.00 Amit | Banda | SA_REP | 6230.00 Charles | Johnson | SA_REP | 6230.00 Sundar | Ande | SA_REP | 6430.00 Susan | Mavris | HR_REP | 6530.00 Shanta | Vollman | Salesman | 6530.00 David | Lee | SA_REP | 6830.00 Luis | Popp | FI_ACCOUNT | 6930.00 Kimberely | Grant | SA_REP | 7030.00 Oliver | Tuvault | SA_REP | 7030.00 Sarath | Sewall | SA_REP | 7030.00 Mattea | Marvins | SA_REP | 7230.00 Elizabeth | Bates | SA_REP | 7330.00 William | Smith | SA_REP | 7430.00 Louise | Doran | SA_REP | 7530.00 ... Lex | De Haan | AD_VP | 17030.00 Neena | Kochhar | AD_VP | 17030.00 Steven | King | AD_PRES | 24030.00 (60 rows)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?