What is a SQL Subquery?
A subquery (also called an inner or nested query) is a query within another query.
Can a subquery be nested in a SELECT clause?
Yes. Subqueries are usually nested in the SELECT, FROM, and/or WHERE clauses.
Can a subquery be nested in a SET query?
Subqueries can’t be nested in SET queries.
What is a SET command used for?
The SET command is used with UPDATE to specify which columns and values that should be updated in a table.
What do you use to assign a value that isn’t NULL to a declared variable?
The SET statement that assigns a value to the variable returns a single value. When initializing multiple variables, use a separate SET statement for each local variable.
Can you use comparison operators such as >, <, or = within queries?
Yes, comparison operators such as >,>, or = help you compare data in subqueries. You can also use multiple row operators, including IN, ANY, or ALL.
What is the statement containing a subquery called?
Outer query or outer select. Subqueries are nested within these statements, called inner queries or inner select.
Does the parent query execute before its inner query?
The innermost query executes first. Its parent query executes last so it can use the results returned by inner queries.
-You can specify up to 16 subqueries within a single SQL statement, and you can specify subqueries within a subquery.
-Subqueries run from last to first within the main SQL statement in which they appear.
True or False: Subqueries don’t have to be enclosed within parentheses.
False. Parentheses are used to mark the beginning and end of a subquery.
Can a subquery have more than one column specified in the SELECT clause?
Specify only one column or expression in a subquery unless you use IN, ANY, ALL, or EXISTS.
What is not allowed in a subquery?
-A subquery cannot contain a BETWEEN or LIKE clause.
-A subquery cannot contain an ORDER BY clause.
-A subquery in an UPDATE statement cannot retrieve data from the same table in which data is to be updated.
-A subquery in a DELETE statement cannot retrieve data from the same table in which data is to be deleted.
LEFT function does…
Returns a set number of characters from the left side of a text string.
LEN function does…
Returns the length of a string of text by counting the number of chars it contains.
FIND function does…
Locate specific characters in a string.
RIGHT function does…
Return a set number of chars from the right side of a text string.