FROM clause
Description
The
FROMclause in a query lists the table references (tables, views, and subqueries) that data is selected from. If multiple table references are listed, the tables must be joined, using appropriate syntax in either theFROMclause or theWHEREclause. If no join criteria are specified, the system processes the query as a cross-join. (Redshift SQL Language Reference FROM Clause)
The FROM clause is partially supported in Snowflake. Object unpivoting is not currently supported.
Grammar Syntax
FROM table_reference [, ...]
<table_reference> ::=
with_subquery_table_name [ table_alias ]
table_name [ * ] [ table_alias ]
( subquery ) [ table_alias ]
table_reference [ NATURAL ] join_type table_reference
[ ON join_condition | USING ( join_column [, ...] ) ]
table_reference PIVOT (
aggregate(expr) [ [ AS ] aggregate_alias ]
FOR column_name IN ( expression [ AS ] in_alias [, ...] )
) [ table_alias ]
table_reference UNPIVOT [ INCLUDE NULLS | EXCLUDE NULLS ] (
value_column_name
FOR name_column_name IN ( column_reference [ [ AS ]
in_alias ] [, ...] )
) [ table_alias ]
UNPIVOT expression AS value_alias [ AT attribute_alias ]Sample Source Patterns
Join types
Snowflake supports all types of joins. For more information, see the JOIN documentation.
Input Code:
Inner Join
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Sofía
Engineering
Left Join
Carlos
null
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Saanvi
null
Shirley
null
Sofía
Engineering
Zhang
null
Right Join
HR
Carlos
Sales
John
Engineering
Jorge
Marketing
Kwaku
null
Liu
null
Mateo
null
Nikki
null
Paulo
null
Richard
null
Saanvi
null
Shirley
null
Sofía
null
Zhang
Full Join
Carlos
null
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Saanvi
null
Shirley
null
Sofía
Engineering
Zhang
null
Output Code:
Inner Join
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Sofía
Engineering
Left Join
Carlos
null
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Saanvi
null
Shirley
null
Sofía
Engineering
Zhang
null
Right Join
HR
Carlos
Sales
John
Engineering
Jorge
Marketing
Kwaku
null
Liu
null
Mateo
null
Nikki
null
Paulo
null
Richard
null
Saanvi
null
Shirley
null
Sofía
null
Zhang
Full Join
Carlos
null
John
HR
Jorge
Sales
Kwaku
Sales
Liu
Sales
Mateo
Engineering
Nikki
Marketing
Paulo
Marketing
Richard
Marketing
Saanvi
null
Shirley
null
Sofía
Engineering
Zhang
null
Pivot Clause
Input Code:
100
1
0
0
0
101
0
3
0
0
102
0
0
2
0
103
0
0
0
3
Output Code:
100
1
0
0
0
101
0
3
0
0
102
0
0
2
0
103
0
0
0
3
Unpivot Clause
Input Code:
RED
15
RED
35
RED
10
GREEN
20
GREEN
23
BLUE
7
BLUE
40
Output Code:
RED
15
GREEN
20
BLUE
7
RED
35
BLUE
40
RED
10
GREEN
23
Related EWIs
SSC-EWI-RS0005: Column aliases cannot be used in the IN clause of the PIVOT/UNPIVOT query in Snowflake.
Last updated
