Subqueries & CTEs · Question 18 · Hard
Subqueries & CTEs question 18
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
What does this query return?
SELECT dept, MAX(salary)
FROM Faculty f
WHERE salary < (SELECT MAX(salary)
FROM Faculty g
WHERE g.dept = f.dept)
GROUP BY dept
ORDER BY dept;
- CSE, 105000; ECE, 75000
- CSE, 105000; ECE, 75000; MECH, 60000
- CSE, 105000
- CSE, 105000; ECE, NULL; MECH, NULL
Answer and explanation
Answer: C. CSE, 105000
Explanation: WHERE keeps only people paid less than their own department's highest salary: Anand and Firoz in CSE. In ECE both earn the maximum and MECH has one person, so those departments have no rows left and form no group.
Previous: Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70… · Next: Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans…
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
- In the query below, how is the inner query logically evaluated?
- Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
- Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
- Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans…
- Tables Members(mid, name) and Loans(loan_id, mid, book) are given, and…
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