100% found this document useful (1 vote)
118 views

Subquery Question

The document discusses correlated subqueries in SQL. It states that: 1) Correlated subqueries can be used within a single SQL statement and can often be replaced by table joins. 2) The subquery within the main SQL statement will be executed once for each record returned by the main query, rather than just once irrespective of the number of main query records. 3) Correlated subqueries can sometimes suffer from performance penalties when used on large tables due to repeated execution for each main query record.

Uploaded by

bayush
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
118 views

Subquery Question

The document discusses correlated subqueries in SQL. It states that: 1) Correlated subqueries can be used within a single SQL statement and can often be replaced by table joins. 2) The subquery within the main SQL statement will be executed once for each record returned by the main query, rather than just once irrespective of the number of main query records. 3) Correlated subqueries can sometimes suffer from performance penalties when used on large tables due to repeated execution for each main query record.

Uploaded by

bayush
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Which of the following statement contains incorrect information about


correlated sub-queries?
a. Multiple sub-queries can be used within a single SQL statement

b. Correlated sub-queries can often be replaced by table joins

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.

d. Correlated sub-queries can sometimes suffer from a heavy performance


penalty especially if they have to act on large tables

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.

Note: Join free Sanfoundry classes at Telegram or Youtube

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.

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
View Answer
Answer: b
Explanation: 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
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.

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
View Answer
Answer: b
Explanation: 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
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

You might also like