CS FundamentalsModerateGATE CS (PYQ pattern)
QA(a, b): (1,2), (2,3), (3,1), (4,4). How many rows does SELECT * FROM QA x JOIN QA y ON x.b = y.a JOIN QA z ON y.b = z.a return?
- A. 4
- B. 3
- C. 5
- D. 6
Correct answer: A. 4
Follow edges a→b two steps: from 1: 1→2→3→1 (x=(1,2), y=(2,3), z=(3,1)); from 2: (2,3),(3,1),(1,2); from 3: (3,1),(1,2),(2,3); from 4: (4,4),(4,4),(4,4). Four starting rows, each with exactly one chain: 4 rows.
More DBMS and SQL questions
- CO(c, n): (a,1), (a,2), (b,3), (b,3), (c,NULL), (c,4). What are COUNT(DISTINCT n), SUM(n), SUM(DISTINCT n) and AVG(n), in that order?
- MT(id, g, v): (1,1,10), (2,1,20), (3,2,30), (4,2,40), (5,2,50), (6,3,60). What does SELECT SUM(v) FROM MT a WHERE v >= (SELECT AVG(v) FROM…
- VW(id, v): (1,5), (2,15), (3,25) and the view BIG = SELECT id, v FROM VW WHERE v > 10. Two more rows (4,8) and (5,30) are then inserted…
- Relation R(A, B) has 6 tuples with 4 distinct values of A and 5 distinct values of B. What are the minimum and maximum possible…
- Relations R and S have 40 and 60 tuples (union-compatible). What are the minimum and maximum cardinalities of R ∪ S, R ∩ S and R − S (in…
- R(A, B) has 1000 tuples; S(B, C) has 500 tuples with B a key of S; T(C, D) has 200 tuples with C a key of T, and S.C is a NOT NULL foreign…