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?

  1. A. 4
  2. B. 3
  3. C. 5
  4. 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

Exams that ask this topic