Relational Queries questions — page 2 of 2

Q46

GATE CS 2017 CS-2Relational QueriesNAT2 marks
Consider the following database table named top_scorer.
playercountrygoals
KloseGermany16
RonaldoBrazil15
G MüllerGermany14
FontaineFrance13
PeléBrazil12
KlinsmannGermany11
KocsisHungary11
BatistutaArgentina10
CubillasPeru10
LatoPoland10
LinekerEngland10
T MüllerGermany10
RahnGermany10
Consider the following SQL query:
SELECT ta.player FROM top_scorer AS ta
WHERE ta.goals > ALL (SELECT tb.goals
                        FROM top_scorer AS tb
                        WHERE tb.country = 'Spain')
AND ta.goals > ANY (SELECT tc.goals
                    FROM top_scorer AS tc
                    WHERE tc.country = 'Germany')
The number of tuples returned by the above SQL query is ____________.
Show answer without attempting

Answer: 7.0

Q52

GATE CS 2016 CS-2Relational QueriesNAT2 marks
Consider the following database table named water_schemes :
scheme_nodistrict_namecapacity
1Ajmer20
1Bikaner10
2Bikaner10
3Bikaner20
1Churu10
2Churu20
1Dungargarh10
The number of tuples returned by the following SQL query is _________.
with total(name, capacity) as
    select district_name, sum(capacity)
    from water_schemes
    group by district_name
with total_avg(capacity) as
    select avg(capacity)
    from total
select name
    from total, total_avg
    where total.capacity ≥ total_avg.capacity
Show answer without attempting

Answer: 2.0

Q29

GATE CS 2015 CS-3Relational QueriesMCQ1 mark−1/3 if wrong
Consider the following relation

Cinema(theater, address, capacity)

Which of the following options will be needed at the end of the SQL query
SELECT P1.address
FROM Cinema P1
such that it always finds the addresses of theaters with maximum capacity?
Show answer without attempting

Answer: A

Q31

GATE CS 2015 CS-1Relational QueriesMCQ1 mark−1/3 if wrong
SELECT operation in SQL is equivalent to
Show answer without attempting

Answer: D

Q61

GATE CS 2015 CS-1Relational QueriesNAT2 marks
Consider the following relations:

Student
Roll_NoStudent_Name
1Raj
2Rohit
3Raj
Performance
Roll_NoCourseMarks
1Math80
1English70
2Math75
3English80
2Physics65
3Math80
Consider the following SQL query.
SELECT S.Student_Name, sum(P.Marks)
FROM Student S, Performance P
WHERE S.Roll_No = P.Roll_No
GROUP BY S.Student_Name
The number of rows that will be returned by the SQL query is ________.
Show answer without attempting

Answer: 2

Q40

GATE CS 2015 CS-2Relational QueriesMCQ2 marks−2/3 if wrong
Consider two relations R1(A,B)R_1(A,B) with the tuples (1,5), (3,7) and R2(A,C)R_2(A,C) = (1,7), (4,9). Assume that R(A,B,C) is the full natural outer join of R1R_1 and R2R_2. Consider the following tuples of the form (A,B,C): a = (1,5,null), b = (1,null,7), c = (3,null,9), d = (4,7,null), e = (1,5,7), f = (3,7,null), g = (4,null,9). Which one of the following statements is correct?
Show answer without attempting

Answer: C

Q30

GATE CS 2014 CS-2Relational QueriesMCQ2 marks−2/3 if wrong
Consider a join (relation algebra) between relations r(R) and s(S) using the nested loop method. There are 3 buffers each of size equal to disk block size, out of which one buffer is reserved for intermediate results. Assuming size(r(R)) < size(s(S)), the join will have fewer number of disk block accesses if
Show answer without attempting

Answer: A

Q54

GATE CS 2014 CS-2Relational QueriesMCQ2 marks−2/3 if wrong
SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives the same answer as the nested query shown below:
select * from R where a in (select S.a from S)
Show answer without attempting

Answer: C

Q21

GATE CS 2014 CS-3Relational QueriesMCQ1 mark−1/3 if wrong
What is the optimized version of the relation algebra expression πA1(πA2(σF1(σF2(r))))\pi_{A1}(\pi_{A2}(\sigma_{F1}(\sigma_{F2}(r)))) where A1,A2A1, A2 are sets of attributes in rr with A1⊂A2A1 \subset A2 and F1,F2F1, F2 are Boolean expressions based on the attributes in rr?
Show answer without attempting

Answer: A

Q30

GATE CS 2014 CS-3Relational QueriesMCQ2 marks−2/3 if wrong
Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee. Assume that every employee has at least one associated dependent in the dependent relation.

employee (empId, empName, empAge)
dependent(depId, eId, depName, depAge)

Consider the following relational algebra query:

ΠempId(employee)−ΠempId(employee⋈(empId=eID)∧(empAge≤depAge)dependent)\Pi_{empId}(\text{employee}) - \Pi_{empId}(\text{employee} \bowtie_{(\text{empId} = \text{eID}) \land (\text{empAge} \le \text{depAge})} \text{dependent})

The above query evaluates to the set of empIds of employees whose age is greater than that of
Show answer without attempting

Answer: D

Q54

GATE CS 2014 CS-3Relational QueriesMCQ2 marks−2/3 if wrong
Consider the following relational schema:

employee(empId,empName,empDept)
customer(custId,custName,salesRepId,rating)

salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
                  FROM customer C
                  WHERE C.salesRepId = E.empId
                  AND C.rating <> 'GOOD');
Show answer without attempting

Answer: D

Q54

GATE CS 2014 CS-1Relational QueriesMCQ2 marks−2/3 if wrong
Given the following schema:
employees(emp-id, first-name, last-name, hire-date, dept-id, salary)
departments(dept-id, dept-name, manager-id, location-id)
You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:
SQL>SELECT last-name, hire-date
 FROM employees
 WHERE (dept-id, hire-date) IN
 (SELECT dept-id, MAX(hire-date)
 FROM employees JOIN departments USING(dept-id)
 WHERE location-id = 1700
 GROUP BY dept-id);
What is the outcome?
Show answer without attempting

Answer: B

Q35

GATE CS 2013 CSRelational QueriesMCQ2 marks−2/3 if wrong
Consider the following relational schema.

Students(rollno: integer‾\underline{\text{rollno: integer}}, sname: string)
Courses(courseno: integer‾\underline{\text{courseno: integer}}, cname: string)
Registration(rollno: integer, courseno: integer‾\underline{\text{rollno: integer, courseno: integer}}, percent: real)

Which of the following queries are equivalent to this query in English?
"Find the distinct names of all students who score more than 90% in the course numbered 107"

(I) SELECT DISTINCT S.sname
FROM Students as S, Registration as R
WHERE R.rollno=S.rollno AND R.courseno=107 AND R.percent > 90
(II) Πsname(σcourseno=107∧percent>90(Registration⋈Students))\Pi_{\text{sname}}(\sigma_{\text{courseno}=107 \wedge \text{percent}>90}(\text{Registration} \bowtie \text{Students}))
(III) {T∣∃S∈Students,∃R∈Registration(S.rollno=R.rollno∧R.courseno=107∧R.percent>90∧T.sname=S.sname)}\{T \mid \exists S \in \text{Students}, \exists R \in \text{Registration} (S.\text{rollno}=R.\text{rollno} \wedge R.\text{courseno}=107 \wedge R.\text{percent}>90 \wedge T.\text{sname}=S.\text{sname})\}
(IV) {⟨SN⟩∣∃SR∃RP(⟨SR,SN⟩∈Students∧⟨SR,107,RP⟩∈Registration∧RP>90)}\{\langle S_N \rangle \mid \exists S_R \exists R_P (\langle S_R, S_N \rangle \in \text{Students} \wedge \langle S_R, 107, R_P \rangle \in \text{Registration} \wedge R_P > 90)\}
Show answer without attempting

Answer: A

Q15

GATE CS 2012 CSRelational QueriesMCQ1 mark−1/3 if wrong
Which of the following statements are TRUE about an SQL query?

P : An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause
Q : An SQL query can contain a HAVING clause only if it has a GROUP BY clause
R : All attributes used in the GROUP BY clause must appear in the SELECT clause
S : Not all attributes used in the GROUP BY clause need to appear in the SELECT clause
Show answer without attempting

Answer: C

Q50

GATE CS 2012 CSRelational QueriesMCQ2 marks−2/3 if wrong
How many tuples does the result of the following relational algebra expression contain? Assume that the schema of A∪BA \cup B is the same as that of AA.

(A∪B)⋈A.Id>40∨C.Id<15C(A \cup B) \bowtie_{A.Id > 40 \lor C.Id < 15} C
Show answer without attempting

Answer: A

Q51

GATE CS 2012 CSRelational QueriesMCQ2 marks−2/3 if wrong
How many tuples does the result of the following SQL query contain?
SELECT A.Id
FROM A
WHERE A.Age > ALL (SELECT B.Age
                   FROM B
                   WHERE B.Name = 'Arun')
Show answer without attempting

Answer: B

0/160 correct0 marks

Related topics in Databases