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 rep FROM Sale WHERE region = 'N' EXCEPT SELECT rep FROM Sale WHERE region = 'S';
- A. Ira, Jai, Kim
- B. Kim, Lal
- C. Ira, Kim
- D. Kim
Correct answer: D. Kim
N reps are {Ira, Jai, Kim}; S reps are {Jai, Ira}. EXCEPT is a set difference with duplicates removed, leaving only Kim.
More DBMS and SQL questions
- R(A, B) = {(1, 1), (1, 3), (3, 2), (4, 1), (4, 2), (4, 4)} and S(B, C) = {(1, 5), (1, 7), (3, 7), (4, 5)}. What is πA(R) − πA(R ⋈ S)?
- R(A, B, C, D, E) has functional dependencies AD → C, B → AE, D → B, AB → D. What is the highest normal form R satisfies?
- R(A, B) = {(1, 2), (1, 4), (2, 4), (4, 1), (4, 2)} and S(B, C) = {(1, 6), (3, 5), (3, 7), (4, 6), (4, 7)}. How many tuples are in πA(R ⋈…
- Consider the schedule R1(A), W2(B), W3(B), R2(B), W1(A), R2(A), W1(B), W3(A). Which statement is correct?
- Σ = {C → B, B → F, F → E, CD → F, DE → B} on R(A, B, C, D, E, F). Exactly one FD in Σ is redundant (it can be derived from the others)…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…