CS FundamentalsVery hardTCS Digital · Infosys SP · GATE CS
Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this query return?
Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5).
What does this query return?
SELECT COUNT(*) FROM Product p
WHERE NOT EXISTS (SELECT * FROM Product q
WHERE q.cat = p.cat AND q.price > p.price);- A. 3
- B. 6
- C. 4
- D. 5
Correct answer: D. 5
Only pid 1 is excluded (pid 2 is pricier in X). pid 2, 3 and 6 are the top of their categories; pid 5's NULL price makes q.price > NULL unknown, and pid 4's NULL category matches no row, so NOT EXISTS is TRUE for both: 5.
More DBMS and SQL questions
- Consider the schedule R3(A), R2(A), R3(B), W3(B), R2(B), W1(B), W1(A), R1(A). Which statement is correct?
- T1: R1(A), R1(B) and T2: W2(A), W2(B). Of all 6 interleavings that keep each transaction's own order, how many are conflict serializable?
- Σ = {CD → A, AC → B, B → E, D → B, C → D} on R(A, B, C, D, E). Exactly one FD in Σ is redundant (it can be derived from the others). Which…
- R(A, B) has 400 tuples and S(B, C) has 80 tuples, where B is the primary key of S, and R.B may contain values absent from S (no foreign…
- Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack'…
- R(A, B) = {(2, 4), (3, 1), (4, 1), (4, 3), (4, 4)} and S(B, C) = {(1, 5), (2, 7), (4, 6), (4, 7)}. How many tuples are in R ⟕ S (left…