PostgreSQL Subquery: Find the name and salary which is equal to the minimum salary for this post he/she is working on

6. Write a SQL subquery to find the first_name, last_name and salary, which is equal to the minimum salary for this post, he/she is working on.

Sample Solution:


SELECT first_name, last_name, salary 
FROM employees 
WHERE employees.salary = 
(SELECT min_salary 
FROM jobs 
WHERE employees.job_id = jobs.job_id);

Sample table: employees

Sample table: jobs


pg_exercises=# SELECT first_name, last_name, salary
pg_exercises-# FROM employees
pg_exercises-# WHERE employees.salary =
pg_exercises-# (SELECT min_salary
pg_exercises(# FROM jobs
pg_exercises(# WHERE employees.job_id = jobs.job_id);
 first_name | last_name  | salary
 Karen      | Colmenares | 2500.00
 Martha     | Sullivan   | 2500.00
 Randall    | Perkins    | 2500.00
(3 rows)

Practice Online

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

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming