w3resource
SQL exercises

SQL Subquery Exercises: Find the first name and last name of employees working for departments which sanction amount is second lowest

SQL SUBQUERY: Exercise-39 with Solution

39. Write a query in SQL to find the first name and last name of employees working for departments which sanction amount is second lowest.

Sample table: emp_department

Sample table: emp_details


Sample Solution:

SELECT emp_fname, emp_lname 
FROM emp_details 
WHERE emp_dept IN (
  SELECT dpt_code
  FROM emp_department 
  WHERE dpt_allotment= (
    SELECT MIN(dpt_allotment)
    FROM emp_department 
    WHERE dpt_allotment >
 (SELECT MIN(dpt_allotment) 
      FROM emp_department )));

Output:

SQL Subqueries : Find the first name and last name of employees working for departments which sanction amount is second lowest

Practice Online


Sample Database:

Model Database

Query Visualization:

Duration:

Query visualization of Find the first name and last name of employees working for departments which sanction amount is second lowest - Duration

Rows:

Query visualization of Find the first name and last name of employees working for departments which sanction amount is second lowest - Rows

Cost:

Query visualization of Find the first name and last name of employees working for departments which sanction amount is second lowest - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to find the names of departments with more than two employees are working.
Next: SQL SORTING and FILTERING on HR Database Exercises Home

What is the difficulty level of this exercise?



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