CS FundamentalsHardGATE CS (PYQ pattern)
ORD(oid, amt): (1,100), (2,200), (3,300). LN(oid, item): (1,a), (1,b), (1,c), (2,a), (3,b), (3,c). PAY(oid, paid): (1,40), (1,60), (3,300). What do SELECT SUM(amt) FROM ORD JOIN LN ON ORD.oid = LN.oid JOIN PAY ON ORD.oid = PAY.oid and the same query with LEFT JOIN PAY instead of JOIN PAY return?
- A. 600 and 600
- B. 1200 and 1400
- C. 1100 and 1400
- D. 1200 and 1200
Correct answer: B. 1200 and 1400
Each order's amt is repeated once per (line, payment) combination. Inner joins: order 1 -> 3 x 2 = 6 rows (600), order 2 has no payment (dropped), order 3 -> 2 x 1 = 2 rows (600): 1200. With LEFT JOIN PAY, order 2 keeps its single line with a NULL payment: +200 = 1400. The true total of orders is 600.
More DBMS and SQL questions
- EM(id, sal, mgr): (1,90,NULL), (2,70,1), (3,70,1), (4,95,2), (5,60,2), (6,40,3), (7,80,3), (8,NULL,4), (9,85,7). How many rows does SELECT…
- Table UP(a, b): (1,10), (2,20), (3,30). After UPDATE UP SET a = b, b = a; (standard SQL semantics), what is the sum of column a and the…
- Table DU(a, b): (1,NULL), (1,NULL), (2,3), (2,3), (NULL,5), (NULL,5), (1,2). Let x = rows returned by SELECT DISTINCT a, b FROM DU, y =…
- R(A, B) and S(B) are relations. Which relational-algebra expression computes the division R ÷ S (the A-values that are paired in R with…
- R(A, B): (1,x), (2,y), (3,z), (4,NULL). S(B, C): (x,10), (x,11), (y,20), (w,30), (NULL,40). How many rows does SELECT FROM R FULL OUTER…
- R(A, B) = {(1,2), (1,3), (2,3), (3,4), (4,1)} is a graph's edge set. How many tuples are in the relation π{A,D}(ρ(R) ⋈{R.B = R2.A} ρ(R2))…