GATE CS 2014 Set 3 — Question 64
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+2 / -0.67MediumSubqueriesSQLDatabases
Databases → SQL → Subqueries
Last updated
Question
Consider the following relational schema:employee(empId, empName, empDept)
customer(custId, custName, salesRepId, rating)
customer(custId, custName, salesRepId, rating)
salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
FROM customer C
WHERE C.salesRepId = E.empId
AND C.rating <> 'GOOD');
Correct answer
(D) Names of all the employees with all their customers having a ‘GOOD’ rating.
Solution
The SQL query selects
empName from the employee table where a certain condition holds.The condition is WHERE NOT EXISTS (...). The subquery selects customers associated with the employee (C.salesRepId = E.empId) who have a rating that is not 'GOOD' (C.rating <> 'GOOD').So, NOT EXISTS returns TRUE if there are no customers for that employee with a rating other than 'GOOD'. In other words, the set of customers with 'BAD' (or any non-GOOD) rating is empty.This implies that all customers associated with the employee must have a rating of 'GOOD'. Since the problem statement assumes each employee makes a sale to at least one customer, we don't need to worry about employees with zero customers (for whom the condition would also be vacuously true).Therefore, the query returns the names of employees where all their customers have a 'GOOD' rating.Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on SQL
2026 Set 2 Q15In the context of DBMS, consider the two sets T and S given below. | T | S | |---|---| | I:…2026 Set 2 Q20Consider concurrent execution of two transactions and in a DBMS, both of which access a…2026 Set 1 Q30Let and be the attributes of a relation in a relational schema. Let…2026 Set 1 Q31In the context of relational database normalization, which of the following statements is/are true?2026 Set 2 Q42In the context of schema normalization in relational DBMS, consider a set F of functional…