- The select statement cannot contain a subquery in the from clause
Then what if I need a list of contents from a subquery?
Create a view or table
I cannot really understand the following three statements
- The select statement cannot refer to system variables or user-defined variables
- Within a stored program, the select statement cannot refer to program parameters or local variables.
- The select statement cannot refer to prepared statement parameters
The confusion ends
- You cannot refer to a temporary table or view
- You cannot associate a trigger with a view
Definer about view
CURRENT_USER
OPTION
View Algorithm
MySQL provides the MERGE
, TEMPTABLE
and UNDEFINED
algorithms to create a view.
MERGE
means the input query will be combined with the SELECT statement of the view definition.
Pro: more efficient than TEMPTABLE
Con: only allowed when the rows in the view represent a one-to-one relationship with the rows in the underlying table.
TEMPTABLE
means MySQL first creates a temporary table based on the SELECT statement of the view definition.
Pro: taken when MERGE
cannot be applied.
Con: less efficient; view is not updatable
UNDEFINED
default; choose automatically by database engine
When MERGE
cannot be used:
if the query contains any of the following constructs:
1. aggregate functions(sum, min, max, count, avg, etc)
2. DISTINCT
3. HAVING
4. LIMIT
5. UNION or UNION ALL
6. Subquery in the select list
7. Refers only to literal values