FROM
constructsupportedQueries & DMLSpecifies the tables, views, or table functions to use in a SELECT statement.
Syntax
supportedpartialnot supportednot scored
SELECT ...
FROM objectReference [ JOIN objectReference [ ... ] ]
[ ... ]
Where
objectReference ::=
{
[<namespace>.]<object_name>
[ AT | BEFORE ( <object_state> ) ]
[ CHANGES ( <change_tracking_type> ) ]
[ MATCH_RECOGNIZE ]
[ PIVOT | UNPIVOT ]
[ [ AS ] <alias_name> ]
[ SAMPLE ]
| <table_function>
[ PIVOT | UNPIVOT ]
[ [ AS ] <alias_name> ]
[ SAMPLE ]
| ( VALUES (...) )
[ SAMPLE ]
| [ LATERAL ] ( <subquery> )
[ [ AS ] <alias_name> ]
| @[<namespace>.]<stage_name>[/<path>]
[ ( FILE_FORMAT => <format_name>, PATTERN => '<regex_pattern>' ) ]
[ [ AS ] <alias_name> ]
| DIRECTORY( @<stage_name> )
| SEMANTIC_VIEW( ... )
| ERROR_TABLE( <base_table_name> )
| DYNAMIC_TABLE_REFRESH_BOUNDARY( <object_name> )
[ AT | BEFORE ( <object_state> ) ]
[ CHANGES ( <change_tracking_type> ) ]
[ [ AS ] <alias_name> ]
}
Parameters
| Name | Required | Description |
|---|---|---|
JOIN | Subclause that specifies to perform a join between two or more tables (or views or table functions). The join can be an inner join, outer join, or other type of join. The join can use the keyword JOIN or an alternative supported join syntax. For more details about joins, see JOIN and ASOF JOIN. | |
[ AS ] alias_name | Specifies a name given to the object reference it is attached to. Can be used with any of the other subclauses in the FROM clause. Alias names must follow the rules for Object identifiers. | |
VALUES | The VALUES clause can specify literal values or expressions to be used in the FROM clause. This clause can contain table and column aliases (not shown in the diagram above). For more details about the VALUES clause, see VALUES. | |
[namespace.]object_name | Specifies the name of the object (table or view) being queried. The object name can be qualified using namespace (in the form of db_name.schema_name.object_name or schema_name.object_name). A namespace is not required if the context can be derived from the current database and schema for the session. When specifying a table/view name to query, you can also specify the following optional subclause:
| |
{ AT | BEFORE } ( object_state ) | Optional subclause that specifies the time-based or event-based historical state of the table or view for Time Travel. For more details, see AT | BEFORE. | |
table_function | Specifies a system-defined table function, a UDF table function, or a class method to call within the FROM clause. For details, see the following topics: Using a table function Calling a UDTF Selecting columns from SQL class instance methods that return tabular data | |
{ PIVOT | UNPIVOT } | Optional subclause that specifies to pivot or unpivot the results of the FROM clause. For more details, see PIVOT and UNPIVOT. | |
SAMPLE | Optional subclause that specifies to sample rows from the table/view. For more details, see SAMPLE / TABLESAMPLE. | |
[ LATERAL ] ( subquery ) | Specifies an inline view within the FROM clause. If the optional LATERAL keyword is used, then the subquery can refer to columns from other tables (or views or table functions) that are in the current FROM clause and to the left of the inline view. For more information about subqueries in general, see Working with Subqueries. | |
@[namespace.]stage_name[/path] | Specifies a named stage to be queried (or ~ for referring to the stage for the current user or % followed by a table name for referring to the stage for the specified table). When querying a stage, you can also optionally specify a named file format and pattern: For more details about querying stages, see Query data in staged files. | |
( FILE_FORMAT => format_name [ , PATTERN => 'regex_pattern' ] ) | Specifies a named file format object to use for the stage and a pattern to filter the set of files in the stage. | |
DIRECTORY( @stage_name ) | Specifies the name of a stage that includes a directory table. | |
hierarchical_query_result | A hierarchical query result is the result set from using a clause such as CONNECT BY to query a table of hierarchical data. For more details, see CONNECT BY. | |
SEMANTIC_VIEW(...) | Specifies the semantic view that you want to query. For information, see SEMANTIC_VIEW. | |
ERROR_TABLE( base_table_name ) | Specifies the name of the base table associated with the error table that you want to query. When error logging is turned on for a table, its error table contains the rows that statements and loads couldn’t write to the table. To query the error table, a role must own the base table, or have both the SELECT privilege and the SELECT ERROR TABLE privilege on it. If a masking policy, a row access policy, or a projection policy is set directly on the base table or on its columns, the role also needs the READ UNREDACTED ERROR TABLE privilege. Masking policies that are assigned through tags don’t require this privilege, so any role that can query the error table sees the original values of the columns that these policies mask. For more information, see Access control requirements for error tables. The following statement queries the error table of the my_table table:Copy code SELECT * FROM ERROR_TABLE(my_table); For more information about error tables, see Error tables. For the errors that COPY INTO and Snowpipe record, see Error logging for COPY INTO and Snowpipe. | |
DYNAMIC_TABLE_REFRESH_BOUNDARY( <object_name> ) | Wraps a table, view, or dynamic table reference so that upstream dynamic tables reachable through it are not refreshed together with the downstream dynamic table. Used in dynamic table definitions to decouple pipelines. For information, see Data consistency and pipeline boundaries. DYNAMIC_TABLE_REFRESH_BOUNDARY() has no effect outside of dynamic table definitions. The wrapped object is read normally. |
Usage notes
- Object names are SQL identifiers. They are case-insensitive by default. To preserve case, enclose them between double quotes (" ").
Parameters
JOIN: Subclause that specifies to perform a join between two or more tables (or views or table functions). The join can be an inner join, outer join, or other type of join. The join can use the keyword JOIN or an alternative supported join syntax. For more details about joins, see JOIN and ASOF JOIN. [ AS ] alias_name: Specifies a name given to the object reference it is attached to. Can be used with any of the other subclauses in the FROM clause. Alias names must follow the rules for Object identifiers. VALUES: The VALUES clause can specify literal values or expressions to be used in the FROM clause. This clause can contain table and column aliases (not shown in the diagram above). For more details about the VALUES clause, see VALUES. [namespace.]object_name: Specifies the name of the object (table or view) being queried. The object name can be qualified using namespace (in the form of db_name.schema_name.object_name or schema_name.object_name). A namespace is not required if the context can be derived from the current database and schema for the session. When specifying a table/view name to query, you can also specify the following optional subclause: { AT | BEFORE } ( object_state ): Optional subclause that specifies the time-based or event-based historical state of the table or view for Time Travel. For more details, see AT | BEFORE. MATCH_RECOGNIZE: Optional subclause for finding sequences of rows that match a pattern. For more details, see MATCH_RECOGNIZE. table_function: Specifies a system-defined table function, a UDF table function, or a class method to call within the FROM clause. For details, see the following topics: Using a table function Calling a UDTF Selecting columns from SQL class instance methods that return tabular data { PIVOT | UNPIVOT }: Optional subclause that specifies to pivot or unpivot the results of the FROM clause. For more details, see PIVOT and UNPIVOT. SAMPLE: Optional subclause that specifies to sample rows from the table/view. For more details, see SAMPLE / TABLESAMPLE. [ LATERAL ] ( subquery ): Specifies an inline view within the FROM clause. If the optional LATERAL keyword is used, then the subquery can refer to columns from other tables (or views or table functions) that are in the current FROM clause and to the left of the inline view. For more information about subqueries in general, see Working with Subqueries. @[namespace.]stage_name[/path]: Specifies a named stage to be queried (or ~ for referring to the stage for the current user or % followed by a table name for referring to the stage for the specified table). When querying a stage, you can also optionally specify a named file format and pattern: For more details about querying stages, see Query data in staged files. ( FILE_FORMAT => format_name [ , PATTERN => 'regex_pattern' ] ): Specifies a named file format object to use for the stage and a pattern to filter the set of files in the stage. DIRECTORY( @stage_name ): Specifies the name of a stage that includes a directory table. hierarchical_query_result: A hierarchical query result is the result set from using a clause such as CONNECT BY to query a table of hierarchical data. For more details, see CONNECT BY. SEMANTIC_VIEW(...): Specifies the semantic view that you want to query. For information, see SEMANTIC_VIEW. ERROR_TABLE( base_table_name ): Specifies the name of the base table associated with the error table that you want to query. When error logging is turned on for a table, its error table contains the rows that statements and loads couldn’t write to the table. To query the error table, a role must own the base table, or have both the SELECT privilege and the SELECT ERROR TABLE privilege on it. If a masking policy, a row access policy, or a projection policy is set directly on the base table or on its columns, the role also needs the READ UNREDACTED ERROR TABLE privilege. Masking policies that are assigned through tags don’t require this privilege, so any role that can query the error table sees the original values of the columns that these policies mask. For more information, see Access control requirements for error tables. The following statement queries the error table of the my_table table:Copy code SELECT * FROM ERROR_TABLE(my_table); For more information about error tables, see Error tables. For the errors that COPY INTO and Snowpipe record, see Error logging for COPY INTO and Snowpipe. DYNAMIC_TABLE_REFRESH_BOUNDARY( <object_name> ): Wraps a table, view, or dynamic table reference so that upstream dynamic tables reachable through it are not refreshed together with the downstream dynamic table. Used in dynamic table definitions to decouple pipelines. For information, see Data consistency and pipeline boundaries. DYNAMIC_TABLE_REFRESH_BOUNDARY() has no effect outside of dynamic table definitions. The wrapped object is read normally.
See also
- AT | BEFORE
- CHANGES
- CONNECT BY
- JOIN
- ASOF JOIN
- MATCH_RECOGNIZE
- PIVOT
- SAMPLE / TABLESAMPLE
- SEMANTIC_VIEW
- UNPIVOT
- Working with joins ↗
- Analyzing time-series data ↗