Subqueries Flashcards
What type of query is used inside another query as if it were a table?
Subquery
Last Revised: 4/2/21, 3.3
True or False: A subquery is always enclosed within parentheses, and it is usually executed prior to its outer query.
True
Last Revised: 4/2/21, 3.5
Put parentheses around your query, give it an alias, and you’ve got a subquery that you can put into the ____________ clause.
FROM
Last Revised: 4/2/21, 3.6
Inline views are another name for ________ ?
Subqueries in the FROM clause of the outer query
Last Revised: 4/2/21, 3.6
What is a candidate key?
(Last Revised: 4/2/21, 3.7)
What operator returns TRUE if the subquery yields any results and FALSE otherwise?
The EXISTS operator
Last Revised: 4/2/21, 3.8
What follows the EXISTS operator?
A subquery
Last Revised: 4/2/21, 3.8
Because the EXISTS operator returns TRUE or FASLE, it can be combined with other Boolean logic such as _____ .
NOT
Last Revised: 4/2/21, 3.8
What clause is the EXISTS operator commonly used in?
The WHERE clause
Last Revised: 4/2/21, 3.8
What is another way to think about latest encounters?
Think of it as “there are no later encounters.” In SQL, that translates to WHERE NOT EXISTS followed by a subquery that returns later encounters
(Last Revised: 4/2/21, 3.8)
What is the extent to which a portion of a query can be referenced elsewhere?
Scope
Last Revised: 4/2/21, 3.10
True or False: An outer query can only reference the results of a subquery, not the data or logic used to create the results.
True
• That means that the outer query can only reference the columns returned by the SELECT clause of the subquery.
(Last Revised: 4/2/21)
What clause does the subquery use to pass columns to the outer query?
The SELECT clause
Last Revised: 4/2/21, 3.10
Can a subquery reference the columns retuned by the FROM clause of the outer query?
Yes
• When a subquery is processed, SQL attempts to resolve references within the subquery; it that fails, then SQL attempts to resolve the reference with columns retuned by the FROM clause in the outer query.
(Last Revised: 4/2/21, 3.10)
What is an Uncorrelated Subquery a result of?
If a subquery doesn’t reference columns from the outer query, it is known as an uncorrelated subquery.
(Last Revised: 4/2/21)