CS FundamentalsModerateAmazon/Flipkart SQL round · GATE CS

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?
SELECT COUNT(DISTINCT rep)
FROM Sale
WHERE region = 'N'
  AND rep IN (SELECT rep FROM Sale WHERE region = 'S');
  1. A. 2
  2. B. 3
  3. C. 1
  4. D. 4

Correct answer: A. 2

N reps: Ira, Kim, Jai, Ira; of these, Ira and Jai also appear in S. DISTINCT counts them once each: 2.

More DBMS and SQL questions

Exams that ask this topic