Question:

Consider the following two tables emp1 and emp2:
emp1
IdName
1Amit
2Punita
emp2
IdName
1Punita
2Anand
What is the output of the following query?
SELECT name from emp1 minus SELECT name from emp2;

Updated On: May 28, 2025
  • Punita
  • Amit
  • Anand
  • Amit, Punita
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Approach Solution - 1

To solve the given query, we need to understand the SQL MINUS operator, which returns distinct rows from the first SELECT statement that aren't present in the results of the second SELECT statement.
Consider the data from both tables:
emp1
IdName
1Amit
2Punita
emp2
IdName
1Punita
2Anand
Now, let's break down the SQL query:
SELECT name from emp1 will produce:
  • Amit
  • Punita
SELECT name from emp2 will produce:
  • Punita
  • Anand
Applying the MINUS operator:
  • Remove the names that appear in both lists.
  • Punita is common in both, so it is removed.
This leaves:
  • Amit
Thus, the output of the query SELECT name from emp1 minus SELECT name from emp2; is:
Amit
Was this answer helpful?
0
0
Hide Solution
collegedunia
Verified By Collegedunia

Approach Solution -2

The output of the SQL query SELECT name FROM emp1 MINUS SELECT name FROM emp2 is amit.

Additional Context:

  • MINUS Operation:
    • Returns distinct rows from first query not present in second
    • Performs set difference operation
    • Equivalent to EXCEPT in some SQL dialects
  • Step-by-Step Execution:
    1. First query results: {'amit', 'punita'}
    2. Second query results: {'punita', 'anand'}
    3. MINUS removes all names appearing in second set
    4. Final result: {'amit'} (only unique to first set)
  • Important Notes:
    • Case-sensitive comparison in most databases
    • Returns only distinct values (duplicates removed)
    • Column count and data types must match
  • Alternative Syntax:
    • LEFT JOIN with NULL check
    • NOT EXISTS subquery

Correct Answer: (2) amit.

Was this answer helpful?
0
0