Question 1
The following are all valid locations in an SQL query for a subquery. According to the text, which is the most commonly used?
Question 1 options:
In the FROM clause as a virtual table
In the WHERE or HAVING clause as a subquery search condition
In the SELECT clause as a scalar value
In the ORDER BY clause as a sort order
Question 2
A subquery comparison as a condition in the WHERE clause can sometimes be used as an alternative to joining tables (i.e. both methods can sometimes be viable solutions). Which of the following is an advantage of using a subquery solution?
Question 2 options:
You can use a subquery to pass an aggregate calculation to the outer query
You can include columns from both tables in the output
The query will typically perform faster
Subquery solutions can be easier to code for short, simple queries
Question 3
The IN comparison can be used in SQL Server to compare a value against a list of hard-coded values; it can also be used to compare against a dynamically-generated list by using a subquery. Which of the following is true for this type of comparison?
Question 3 options:
The subquery must return a single column of values
The subquery must return a single row of values
The subquery must return a single value
The subquery must include a correlation
Question 4
When using a comparison operator (e.g. = > < >= <= etc.) against a subquery, the subquery must return a single value (one row, one column); otherwise an error will result. What is one method to make this type of comparison and avoid the error?
Question 4 options:
Convert numeric values to strings
Include multiple columns in your SELECT clause
Code the condition with one of the keywords ANY, SOME, or ALL
Write the subquery using an aggregate calculation
Question 5
WHERE clause comparisons against a subquery can use comparison operators (e.g. + > < >= <= etc.). What is the effect when the ALL keyword is applied to this type of comparison?
Question 5 options:
The comparison will now be true when multiple rows are returned
The comparison will now be false if the subquery returns no rows
The condition must now be true for every value returned from the subquery
The condition can now be true for any value returned from the subquery
Question 6
WHERE clause comparisons against a subquery can use comparison operators (e.g. + > < >= <= etc.). TheANY and SOME keywords can be applied to this type of comparison to match part of the returned set of values. What is the functional difference between ANY and SOME?
Question 6 options:
None of the above; they are equivalent
ANY works only against the equality operator ( + )
The ANY comparison will typically return more values
The SOME comparison will typically return more values
Question 7
Which of the following are true about correlated subqueries when used in WHERE clause conditions? Check only those that apply:
Question 7 options:
When using the same table as the outer query, they require the use of an alias
They refer to a value provided by a column in the outer query
They are executed once for each row processed by the outer query
They typically run more efficiently than non-correlated subqueries
For testing, they can be executed independently from the outer query without modification
Question 8
Which of the following is true when using the EXISTS comparison against a subquery in the WHERE clause?
Question 8 options:
Values the subquery can be displayed in the output
You cannot use a correlation in the subquery
The subquery must SELECT only a single column
It resolves as true when the subquery returns any rows
Question 9
A subquery can be placed in the FROM clause of an outer query to act as a kind of "virtual" table (it must be assigned an alias, and all calculated values must be given labels). What is the name given to this type of subquery?
Question 9 options:
A view table
A formulated table
A derived table
A calculated table
Question 10
Which is true when using a subquery in the SELECT clause of an outer query?
Question 10 options:
They can return multiple columns, but only a single row
They can return any number of rows and columns
They must return only a single value
They can return multiple rows, but only a single column