SQL Exercise: List the employees who are senior to ADELYN
SQL subqueries on employee Database: Exercise-9 with Solution
[An editor is available at the bottom of the page to write and execute the scripts.]
9. From the following table, write a SQL query to find those employees who are senior to ADELYN. Return complete information about the employees.
Sample table: employees
Sample Solution:
SELECT *
FROM employees
WHERE hire_date <
(SELECT hire_date
FROM employees
WHERE emp_name = 'ADELYN');
Sample Output:
emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id --------+----------+----------+------------+------------+--------+------------+-------- 63679 | SANDRINE | CLERK | 69062 | 1990-12-18 | 900.00 | | 2001 (1 row)
Explanation:
The said query in SQL that retrieves all employees who were hired before the employee named 'ADELYN' from the 'employees' table.
The WHERE clause in the main query filters the results to only include rows where the hire_date is earlier than the hire_date of the employee named 'ADELYN' which is obtained from the subquery .
The subquery, that selects the hire_date of the employee named 'ADELYN' 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 with the same designation as FRANK.
Next SQL Exercise: Personnel with department ID 2001 and ID 1001.
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-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics