Snowflake Union() Function: Syntax & Example - The Hard Way vs The Easy Way
By Brian Laleye · September 20, 2022 · 4 min read
Difficulty Level: Basic
In this article, we will discuss how to use the Snowflake Union() function.
This function is a built-in operation used for handling data sets.
Let’s dive into why this function exists and how to use it in both Code & No Code.
Summary
What is the Snowflake Union() function?
Snowflake Union() function
Definition:
It aggregates two data sets and removes duplicates if any.
Snowflake Union All() function
Definition:
It aggregates two data sets without removing duplicates if any.
Snowflake Union & Union All() functions
Requirements to use them properly:
- The two datasets need to have the same schema or structure (same name of columns in the same order).
- Each column of both datasets needs to have the same data type (integer, string..).
How to use Snowflake Union() function: The Hard Way With Code
Snowflake Union() function
1. Syntax
SELECT...
UNION
SELECT...
2. Examples
- Input
SELECT C1, C2, C3, C3 FROM TABLE_A
UNION
SELECT C1, C2, C3 FROM TABLE_B
- Output:
The above Snowflake Union() example demonstrates that the duplicates have been removed since this function doesn’t let them.
Snowflake Union ALL() function
1. Syntax
SELECT ALL...
UNION
SELECT...
2. Examples
- Input
SELECT C1, C2, C3, C3 FROM TABLE_A
UNION ALL
SELECT C1, C2, C3 FROM TABLE_B
- Output:
The above Snowflake Union All() example demonstrates that the duplicates have not been removed since this function lets them.
With RestApp, be your team’s data hero
by activating insights from raw data sources.
How to use Snowflake Union() function: The Easy Way Without Coding
Snowflake Union() function
1. Syntax
2. Examples
- Input
- Output:
The above built-in Snowflake Union() function example demonstrates that the duplicates have been removed since this function lets them.
Snowflake Union All() function
1. Syntax
2. Examples
- Input
- Output:
Conclusion
At RestApp, we’re building a Data Activation Platform for modern data teams.
We designed our next-gen data modeling editor to be intuitive and easy to use.
If you’re interested in starting your data journey, check out our website and create your free account.
Discover a quick video of our end-to-end No Code data pipeline platform.
Category
Subscribe to our newsletter
Additional resources:
Build better data pipelines
With RestApp, be your team’s data hero by activating insights from raw data sources.
With RestApp, be your team’s data hero
by activating insights from raw data sources.