Subqueries & CTEs · Question 11 · Medium

Subqueries & CTEs question 11

Table Faculty:
fid | name | dept | salary
1 | Anand | CSE | 90000
2 | Bhavna | CSE | 120000
3 | Charu | ECE | 75000
4 | Dhruv | ECE | 75000
5 | Esha | MECH | 60000
6 | Firoz | CSE | 105000

Which names does this query return?

SELECT f.name
FROM Faculty f
JOIN (SELECT dept, MIN(salary) AS low
      FROM Faculty
      GROUP BY dept) d
  ON f.dept = d.dept AND f.salary = d.low
ORDER BY f.name;
  1. Esha
  2. Anand; Charu; Esha
  3. Anand; Esha
  4. Anand; Charu; Dhruv; Esha
Answer and explanation

Answer: D. Anand; Charu; Dhruv; Esha

Explanation: The derived table holds the lowest salary of each department: CSE 90000, ECE 75000, MECH 60000. Joining back on both dept and salary returns everyone who earns that minimum, so both Charu and Dhruv appear for ECE.

Previous: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |… · Next: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…

Practise subqueries & ctes

Try a fresh set of subqueries & ctes questions with an explanation after every answer, free and without signing up: Subqueries & CTEs practice. Or sit a full placement mock test.

More subqueries & ctes questions

More sql practice

Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge