SQL Exercise: List the employees with the same designation as FRANK.
SQL subqueries on employee Database: Exercise-8 with Solution
[An editor is available at the bottom of the page to write and execute the scripts.]
8. From the following table, write a SQL query to find those employees who work as same designation of FRANK. Return complete information about the employees.
Sample table: employees
Sample Solution:
SELECT *
FROM employees
WHERE job_name =
(SELECT job_name
FROM employees
WHERE emp_name = 'FRANK');
Sample Output:
emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id --------+----------+----------+------------+------------+---------+------------+-------- 67858 | SCARLET | ANALYST | 65646 | 1997-04-19 | 3100.00 | | 2001 69062 | FRANK | ANALYST | 65646 | 1991-12-03 | 3100.00 | | 2001 (2 rows)
Explanation:
The said query in SQL that selects all employees who have the same job_name as the employee named 'FRANK' from the 'employees' table.
The WHERE clause in the main query filters the results to only include rows where the job_name is the same as the job_name of the employee named 'FRANK' which is determined by a subquery.
The subquery, which selects the job_name of the employee named 'FRANK' from the 'employees' table.
Practice Online
Structure of employee Database:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: List the employees whose salary is more than JONAS.
Next SQL Exercise: List the employees who are senior to ADELYN.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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-8.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics