Get a record from the specified view. The fields to get have to be already in the view. It produces one or zero static record and costs little time.
SELECT <* | column_name [AS field_alias] [, ...]> FROM view_name WHERE column_name = constant;
Selecting from a view is a very fast operation that takes advantage of the concept of a view. So it has a more restricted syntax than selecting from a stream:
- The most important difference between
SELECTfrom a stream and from a view is that the former has an
EMIT CHANGESclause and the latter does not.
SELECTclause can only contain
*or column names with/without aliases. Other ones such as constants, arithmetical expressions, aggregate/scalar functions, etc. are not allowed. And the column names should be in the
SELECTclause of the query when creating the corresponding view.
FROMclause can only contain ONE view name. Clauses such as
JOINare not allowed.
WHEREclause can only contain ONE conditional expression in the form of
column_name = constant. And the
column_namehas to be the same as which in the
GROUP BYclause when creating the corresponding view and the
constanthas to be a literal whose value is known at compile time, see constant.
// Assume that this query has been executed successfully before // CREATE VIEW my_view AS SELECT a, b, SUM(a), COUNT(*) AS cnt FROM foo GROUP BY b EMIT CHANGES; SELECT `SUM(a)`, cnt, a FROM my_view WHERE b = 1;