GateAI
SQL

GATE CSE 2014 Set 3 · Q54

MCQ2 marksMedium

Time

Consider the following relational schema: employee(empId, empName, empDept)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');

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) Names of all the employees with all their customers having a ‘GOOD’ rating.

SQL

Let us analyze the query step by step:

  1. The outer query selects empName from the employee relation with alias E.

  2. The correlated subquery inside NOT EXISTS searches for any customer assigned to employee E (C.salesRepId = E.empId) whose rating is NOT 'GOOD' (C.rating <> 'GOOD').

  3. The WHERE NOT EXISTS condition evaluates to TRUE if and only if the subquery returns an empty result set, meaning there does not exist any customer of employee E with a rating other than 'GOOD'.

  4. Since it is given that every employee has made a sale to at least one customer, having no customers with a rating other than 'GOOD' means that all customers of that employee have a rating of 'GOOD'.

Therefore, the query returns the names of all employees with all their customers having a 'GOOD' rating (Option D).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q54 of the GATE CSE 2014 Set 3 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2014 Set 3.

How GATE tests SQL

More from GATE CSE 2014 Set 3

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 3 · Q54 · MCQ

Consider the following relational schema: employee(empId, empName, empDept) 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');

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.