CS FundamentalsHardGATE CS (PYQ pattern)
Tables D(d): 1, 2, 3, 4. E(e, d, sal): (10,1,60), (11,1,40), (12,2,30), (13,3,70), (14,3,80), (15,NULL,90). How many rows does SELECT * FROM D LEFT JOIN E ON D.d = E.d AND E.sal > 50 return?
- A. 3
- B. 6
- C. 5
- D. 7
Correct answer: C. 5
The sal > 50 test is part of the join condition, so unmatched D rows are still kept with NULLs: d=1 matches (10), d=2 none, d=3 matches 13 and 14, d=4 none = 5 rows. Putting the test in WHERE would give 3; no test gives 6.
More DBMS and SQL questions
- T(x) holds 1, 2, 3, 4, 5, 6, NULL and U(y) holds 2, 4, NULL. Let a, b, c be the row counts of (a) SELECT FROM T WHERE x NOT IN (SELECT y…
- Table S(id, v): (1,10), (2,20), (3,20), (4,30), (5,30), (6,40). SELECT SUM(v) OVER (ORDER BY v) AS s FROM S ORDER BY id; What is the sum…
- Table P(n, s): (a,90), (b,85), (c,85), (d,70), (e,70), (f,70), (g,60). A query computes r = RANK() OVER (ORDER BY s DESC) and d =…
- Table W(id, dept, sal): (1,A,50), (2,A,70), (3,A,90), (4,B,40), (5,B,40), (6,C,100), (7,C,20), (8,C,NULL), (9,D,NULL). SELECT COUNT() FROM…
- A1(x) holds 1, 1, 1, 2, 2, 3, NULL, NULL and B1(x) holds 1, 2, 2, 2, NULL, 4. Using the standard bag semantics (a value occurring m times…
- Tables ST(s, c) with rows (p,DB), (p,OS), (p,CN), (q,DB), (q,OS), (r,DB), (r,OS), (r,CN), (r,AI), (s,CN), (s,OS), (s,DB), (s,DB) and…