CS FundamentalsHardGATE CS
R(x) = (1, 2, 2, 3, NULL, NULL, 5), S(x) = (2, 3, 3, NULL, 6), T(x) = (2, 2, 3, NULL, 5, 7) (one column each). How many rows does (SELECT x FROM R UNION ALL SELECT x FROM S) INTERSECT (SELECT x FROM T) return? (INTERSECT removes duplicates and treats NULLs as equal.)
- A. 4
- B. 6
- C. 5
- D. 2
Correct answer: A. 4
The UNION ALL has all 12 values; INTERSECT with T keeps each distinct value present on both sides once. Values 2, 3 and NULL are common, but 5 also appears in both (R has 5, T has 5): the result has 4 rows. Treating NULL as unequal would lose one row.
More DBMS and SQL questions
- P(g, v) = (a, 5), (a, 7), (a, 7), (b, 3), (b, NULL), (b, 9), (c, 4), (c, 4), (d, NULL), (NULL, 1), (NULL, 2). How many rows does SELECT…
- T(g, v) = (g1, 5), (g1, 15), (g2, 8), (g2, 9), (g2, NULL), (g3, 50), (g4, NULL), (g4, NULL), (g5, 12), (g5, 3). How many groups does…
- Tk(s, c) = (s1, c1), (s1, c2), (s1, c3), (s2, c1), (s2, c2), (s3, c1), (s3, c2), (s3, c3), (s3, c4), (s4, c3), (s5, c2), (s5, c3), (s5…
- M(s) holds the scores 90, 85, 85, 80, 80, 80, 70, 70, 60. What is the sum over all nine rows of (RANK() OVER (ORDER BY s DESC)…
- A(x) = (3, 5, NULL, 8, 9, 12) and B(x) = (4, NULL, 6). How many rows does SELECT x FROM A WHERE x > ALL (SELECT x FROM B) return? (ALL is…
- R(A, B) has 5000 tuples with V(R, B) = 100 distinct B values. S(B, C) has 3000 tuples with V(S, B) = 300 and V(S, C) = 60. Using the…