Snowflake Union() Function_ Syntax & Example

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.

What is the Snowflake Union() function?

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:

  1. The two datasets need to have the same schema or structure (same name of columns in the same order).
  2. 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: 
Snowflake Union function 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: 
Snowflake Union ALL() function Output example

The above Snowflake Union All() example demonstrates that the duplicates have not been removed since this function lets them.

How to use Snowflake Union() function: The Easy Way Without Coding

Snowflake Union() function

1. Syntax

Snowflake Union() function - Syntax - RestApp

2. Examples

  • Input
Snowflake Union() function - Input - RestApp
  • Output: 
Snowflake Union() function - Preview - RestApp

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

Snowflake Union All() function - Syntax - RestApp

2. Examples

  • Input
Snowflake Union All() function - Input - RestApp
  • Output: 
Snowflake Union All() function - Preview - RestApp

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.

Play Video about Analytics Engineers - Data Pipeline Feature - #1

Category

Share

Subscribe to our newsletter

Brian Laleye
Brian Laleye
Brian is the co-founder of RestApp. He is a technology evangelist and passionate about innovation. He has an extensive experience focusing on modern data stack.
Share this article
Subscribe to our newsletter

Build better data pipelines

With RestApp, be your team’s data hero by activating insights from raw data sources.