SnowConvert AI - Redshift - SELECT¶
SELECT¶
Description¶
Returns rows from tables, views, and user-defined functions. (Redshift SQL Language Reference SELECT statement)
Grammar Syntax¶
For more information please refer to each of the following links:
CONNECT BY clause¶
Description¶
The CONNECT BY clause specifies the relationship between rows in a hierarchy. You can use CONNECT BY to select rows in a hierarchical order by joining the table to itself and processing the hierarchical data. (Redshift SQL Language Reference CONNECT BY Clause)
Note
The CONNECT BY clause is supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
COUNT(*) |
|---|
12 |
Output Code:¶
Snowflake¶
Results¶
COUNT(*) |
|---|
12 |
FROM clause¶
Description¶
The FROM clause 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 the FROM clause or the WHERE clause. If no join criteria are specified, the system processes the query as a cross-join. (Redshift SQL Language Reference FROM Clause)
Warning
The FROM clause is partially supported in Snowflake. Object unpivoting is not currently supported.
Grammar Syntax¶
Sample Source Patterns¶
Join types¶
Snowflake supports all types of joins. For more information, see the JOIN documentation.
Input Code:¶
Redshift¶
Results¶
Inner Join¶
| EMPLOYEE_NAME | DEPARTMENT_NAME |
|---|---|
| John | HR |
| Jorge | Sales |
| Kwaku | Sales |
| Liu | Sales |
| Mateo | Engineering |
| Nikki | Marketing |
| Paulo | Marketing |
| Richard | Marketing |
| Sofía | Engineering |
Left Join¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
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¶
DEPARTMENT_NAME |
MANAGER_NAME |
|---|---|
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¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
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:¶
Snowflake¶
Results¶
Inner Join¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
John |
HR |
Jorge |
Sales |
Kwaku |
Sales |
Liu |
Sales |
Mateo |
Engineering |
Nikki |
Marketing |
Paulo |
Marketing |
Richard |
Marketing |
Sofía |
Engineering |
Left Join¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
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¶
DEPARTMENT_NAME |
MANAGER_NAME |
|---|---|
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¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
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¶
Note
Column aliases cannot be used in the IN clause of the PIVOT query in Snowflake.
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
‘HR’ |
‘Sales’ |
‘Engineering’ |
‘Marketing’ |
|---|---|---|---|---|
100 |
1 |
0 |
0 |
0 |
101 |
0 |
3 |
0 |
0 |
102 |
0 |
0 |
2 |
0 |
103 |
0 |
0 |
0 |
3 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
‘HR’ |
‘Sales’ |
‘Engineering’ |
‘Marketing’ |
|---|---|---|---|---|
100 |
1 |
0 |
0 |
0 |
101 |
0 |
3 |
0 |
0 |
102 |
0 |
0 |
2 |
0 |
103 |
0 |
0 |
0 |
3 |
Unpivot Clause¶
Note
Column aliases cannot be used in the IN clause of the UNPIVOT query in Snowflake.
Input Code:¶
Redshift¶
Results¶
COLOR |
CNT |
|---|---|
RED |
15 |
RED |
35 |
RED |
10 |
GREEN |
20 |
GREEN |
23 |
BLUE |
7 |
BLUE |
40 |
Output Code:¶
Snowflake¶
Results¶
COLOR |
CNT |
|---|---|
RED |
15 |
GREEN |
20 |
BLUE |
7 |
RED |
35 |
BLUE |
40 |
RED |
10 |
GREEN |
23 |
Related EWIs¶
SSC-EWI-RS0005: SnowConvert AI translation for column aliases in the PIVOT/UNPIVOT IN clause is pending.
GROUP BY clause¶
Description¶
The GROUP BY clause identifies the grouping columns for the query. Grouping columns must be declared when the query computes aggregates with standard functions such as SUM, AVG, and COUNT. (Redshift SQL Language Reference GROUP BY Clause)
Note
The GROUP BY clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Grouping sets¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Group by Cube¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Group by Rollup¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
null |
1 |
null |
13 |
Related EWIs¶
There are no known issues.
HAVING clause¶
Description¶
The HAVING clause applies a condition to the intermediate grouped result set that a query returns. (Redshift SQL Language Reference HAVING Clause)
Note
The HAVING clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
101 |
3 |
103 |
3 |
104 |
3 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
101 |
3 |
103 |
3 |
104 |
3 |
Related EWIs¶
There are no known issues.
ORDER BY clause¶
Description¶
The ORDER BY clause sorts the result set of a query. (Redshift SQL Language Reference Order By Clause)
Note
The ORDER BY clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
107 |
Liu |
103 |
108000.00 |
103 |
Kwaku |
101 |
105000.00 |
102 |
Jorge |
101 |
95000.00 |
106 |
Mateo |
103 |
95000.00 |
108 |
Zhang |
104 |
95000.00 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
107 |
Liu |
103 |
108000.00 |
103 |
Kwaku |
101 |
105000.00 |
102 |
Jorge |
101 |
95000.00 |
106 |
Mateo |
103 |
95000.00 |
108 |
Zhang |
104 |
95000.00 |
Related EWIs¶
There are no known issues.
QUALIFY clause¶
Description¶
The QUALIFY clause filters results of a previously computed window function according to user‑specified search conditions. You can use the clause to apply filtering conditions to the result of a window function without using a subquery. (Redshift SQL Language Reference QUALIFY Clause)
Note
The QUALIFY clause is supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
SS_SOLD_DATE |
SS_SOLD_TIME |
SS_ITEM |
SS_SALES_PRICE |
|---|---|---|---|
2022-01-01 |
17:00:00 |
Product 4 |
1000 |
2022-01-01 |
18:00:00 |
Product 5 |
30 |
2022-01-02 |
16:00:00 |
Product 7 |
5 |
Output Code:¶
Snowflake¶
Results¶
SS_SOLD_DATE |
SS_SOLD_TIME |
SS_ITEM |
SS_SALES_PRICE |
|---|---|---|---|
2022-01-02 |
16:00:00 |
Product 7 |
5 |
2022-01-01 |
17:00:00 |
Product 4 |
1000 |
2022-01-01 |
18:00:00 |
Product 5 |
30 |
Related EWIs¶
There are no known issues.
SELECT list¶
Description¶
The SELECT list names the columns, functions, and expressions that you want the query to return. The list represents the output of the query. (Redshift SQL Language Reference SELECT list)
Note
The query start options are fully supported in Snowflake. Just keep in mind that in Snowflake the DISTINCT and ALL options must go at the beginning of the query.
Note
In Redshift, if your application allows foreign keys or invalid primary keys, it can cause queries to return incorrect results. For example, a SELECT DISTINCT query could return duplicate rows if the primary key column does not contain all unique values. (Redshift SQL Language Reference SELECT list)
Grammar Syntax¶
Sample Source Patterns¶
Top clause¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
100 |
Carlos |
null |
101 |
John |
100 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
100 |
Carlos |
null |
101 |
John |
100 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
ALL ¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
101 |
101 |
102 |
103 |
103 |
103 |
104 |
104 |
102 |
104 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
101 |
101 |
102 |
103 |
103 |
103 |
104 |
104 |
102 |
104 |
DISTINCT¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
102 |
103 |
104 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
102 |
103 |
104 |
Related EWIs¶
There are no known issues.
UNION, INTERSECT, and EXCEPT¶
Description¶
The UNION, INTERSECT, and EXCEPT set operators are used to compare and merge the results of two separate query expressions. (Redshift SQL Language Reference Set Operators)
Note
Set operators are fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
103 |
Kwaku |
101 |
110 |
Liu |
101 |
102 |
Jorge |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
Related EWIs¶
There are no known issues.
WHERE clause¶
Description¶
The
WHEREclause contains conditions that either join tables or apply predicates to columns in tables. (Redshift SQL Language Reference WHERE Clause)
Note
The WHERE clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
102 |
Jorge |
101 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
102 |
Jorge |
101 |
Related EWIs¶
There are no known issues.
WITH clause¶
Description¶
A WITH clause is an optional clause that precedes the SELECT list in a query. The WITH clause defines one or more common_table_expressions. Each common table expression (CTE) defines a temporary table, which is similar to a view definition. You can reference these temporary tables in the FROM clause. (Redshift SQL Language Reference WITH Clause)
Note
The WITH clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Recursive form¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
110 |
Liu |
101 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
201 |
Sofía |
102 |
106 |
Mateo |
102 |
105 |
Richard |
103 |
104 |
Paulo |
103 |
110 |
Nikki |
103 |
205 |
Zhang |
104 |
120 |
Saanvi |
104 |
200 |
Shirley |
104 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
110 |
Nikki |
103 |
104 |
Paulo |
103 |
105 |
Richard |
103 |
120 |
Saanvi |
104 |
200 |
Shirley |
104 |
205 |
Zhang |
104 |
Non recursive form¶
Input Code:¶
Redshift¶
Results¶
EMPLOYEE |
MANAGER |
|---|---|
Carlos |
null |
John |
Carlos |
Jorge |
John |
Kwaku |
John |
Liu |
John |
Mateo |
Jorge |
Sofía |
Jorge |
Nikki |
Kwaku |
Paulo |
Kwaku |
Richard |
Kwaku |
Saanvi |
Paulo |
Shirley |
Paulo |
Zhang |
Paulo |
Output Code:¶
Snowflake¶
Results¶
EMPLOYEE |
MANAGER |
|---|---|
John |
Carlos |
Jorge |
John |
Kwaku |
John |
Liu |
John |
Mateo |
Jorge |
Sofía |
Jorge |
Nikki |
Kwaku |
Paulo |
Kwaku |
Richard |
Kwaku |
Saanvi |
Paulo |
Shirley |
Paulo |
Zhang |
Paulo |
Carlos |
null |
Related EWIs¶
There are no known issues.