UGC-NET Jul 2016 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0015

Consider the following ORACLE relations:
R(A, B, C)={<1, 2, 3>, <1, 2, 0>, <1, 3, 1>, <6, 2, 3>, <1, 4, 2>, <3, 1, 4>}
S(B, C, D)={<2, 3, 7>, <1, 4, 5>, <1, 2, 3>, <2, 3, 4>, <3, 1, 4>}
Consider teh following two SQL queries: SQ$_1$; SELECT R.B, AVG(S.B) FROM R, S WHERE R.A=S.C AND S.D<7 GROUP BY R.B SQ$_2$: SELECT DISTINCT S.B, MIN(S-C) FROM S GROUP BY S.B HAVING COUNT (DISTINCT S.D)>1; If M is the number of tuples returned by SQ$_1$ and If N is the number of tuples returned by SQ$_2$ then
  1. A
    M=4, N=2
  2. B
    M=5, N=3
  3. C
    M=2, N=2
  4. D
    M=3, N=3

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionSQ1: the S rows with \(D<7\) are \((1,4,5),(1,2,3),(2,3,4),(3,1,4)\). Join them on R.A = S.C. R rows with \(A=1\) match S \((3,1,4)\), giving R.B values 2, 2, 3, 4. R row \((3,1,4)\) matches S \((2,3,4)\), giving R.B value 1. R row \((6,2,3)\) has no match. The groups by R.B are \(\{1,2,3,4\}\), so \(M=4\). SQ2: group S by B. \(B=1\): D values \(\{5,3\}\), 2 distinct, kept. \(B=2\): \(\{7,4\}\), kept. \(B=3\): \(\{4\}\), dropped. So \(N=2\).Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com