Subquery Question
Subquery Question
c. The sub-query within the main SQL statement will be executed only once
irrespective of the number of records returned by the main query.
2.
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
View Answer
Answer: a
Explanation: 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
View Answer
Answer: d
Explanation: 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
View Answer
Answer: b
Explanation: Nested Subqueries can be used for comparing two different sets. Set
comparison is an important function of the nested sub-queries.
advertisement
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
View Answer
Answer: b
Explanation: 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
View Answer
Answer: a
Explanation: 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
View Answer
Answer: d
Explanation: 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.
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
View Answer
Answer: unique
Explanation: 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
View Answer
Answer: a
Explanation: 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.
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
View Answer
Answer: d
Explanation: 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