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:
Code:
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
Output:
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.
Previous: Write a SQL subquery to find the first_name, last_name and salary, which is greater than the average salary of the employees.
Next: Write a SQL Subquery to find the first_name, last_name and salary of the employees who earn more than the average salary and works in any of the IT departments.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework