RDBMS Multiple Choice Questions on “Nested SubQueries”.
1. What is a subquery?
a) A subquery is a select-from-where expression that is nested within another query
b) A subquery is any query that is nested within another query
c) A subquery is a relation that is externally specified which can be used to handle data in queries
d) A subquery is a condition that excludes all the invalid tuples from the database
Answer: a
Clarification: A subquery is a select-from-where expression that is nested within another query. Common uses for sub-queries are to perform tests for set membership, make set comparisons etc.
2. If a set is a collection of values given by the select clause, The ______ connective tests for set membership
a) within
b) include
c) under
d) in
Answer: d
Clarification: The in connective is used to test for the membership in a set, where the set is a collection of values given by the select clause.
3. State true or false : Nested Subqueries cannot be used for comparing two different sets
a) True
b) False
Answer: b
Clarification: Nested Subqueries can be used for comparing two different sets. Set comparison is an important function of the nested sub-queries.
4. What is the result of the following query?
SELECT studname FROM college WHERE marks > SOME (SELECT marks FROM student WHERE SECTION = 'c');
a) The query gives all the studnames for which marks are greater than all the students in section c
b) The query gives all the studnames for which the marks are greater than at least on student in section c
c) The query gives all the studnames for which the marks are less than all the students in section c
d) The query is syntactically incorrect
Answer: b
Clarification: The “some” comparison is used to check for at least one condition. The > symbol is used to test whether the marks are greater than the right hand side or not.
5. The ________ comparison checker is used to check “each and every” condition
a) all
b) and
c) every
d) each
Answer: a
Clarification: The all comparison checker is used to check “each and every” condition. The “each” and “every” comparison checkers do not exist in SQL.
6. The ______ construct returns true if a given tuple is present in the subquery.
a) not exists
b) present
c) not present
d) exists
Answer: d
Clarification: The exists construct returns true if a given tuple is present in the subquery. The not exists construct gives true if a given tuple is not present in the subquery.
7. What is a correlated sub-query?
a) An independent query that uses the correlation name of another independent query.
b) A sub-query that uses the correlation name of an outer query
c) A sub-query that substitutes the names of the outer query
d) A sub-query that does not depend on its outer query’s correlation names
Answer: b
Clarification: A correlated sub-query is the one that uses the correlation name of an outer query.
8. The _________ construct returns true if the argument in the sub-query is void of duplicates
a) not null
b) not unique
c) unique
d) null
Answer: unique
Clarification: The unique construct returns true if the argument in the sub-query is void of duplicates. The not null construct avoids the specification of null values into the attribute.
9. State true or false: We can use Subqueries inside the from clause
a) True
b) False
Answer: a
Clarification: SQL allows the use of Subqueries inside the from clause. The subquery used in the from clause must have in its result the attributes that are specified in the select clause.
10. Choose the correct option regarding the following query
WITH max_marks (VALUE) AS (SELECT MAX(marks) FROM student) SELECT studentID FROM student,max_marks WHERE student.marks = max_marks.value;
a) The query is syntactically wrong
b) The query gives the studentID of the student with the maximum marks
c) The query gives the maximum marks amongst all the students
d) The query gives all the studentID values except the student with the maximum marks
Answer: b
Clarification: The query gives the studentID with the maximum marks because the max(marks) aggregation gives the maximum of the marks.
11. SQL subqueries that can occur wherever a value is permitted provided the subquery gives only one tuple with a single attribute are called _________
a) Exact Subqueries
b) Vector Subqueries
c) Positive Subqueries
d) Scalar Subqueries
Answer: d
Clarification: SQL subqueries that can occur wherever a value is permitted provided the subquery gives only one tuple with a single attribute are called Scalar subqueries. Scalar Subqueries can be used in the SQL update statement when they are used under the set clause.