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.

Build Better Data Pipelines

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

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.

Build Better Data Pipelines

With RestApp, be your team’s data hero

by activating insights from raw data sources.

Product
Activate and combine any data sources without code

Transform your data with our No Code SQL, Python and NoSQL functions

Run automatically your data pipelines and sync modeled data with your favorite tools

Share your pipelines and collaborate smarter with your teammates

Discover how Data Transformation really means

Find out the new data architecture concept of Data Mesh

Learn how Operational Analytics actives your data

Learn how to deliver great customer experience with real-time data

Solutions

Crunch data at scale with ease

Configure connectors, no build

Save time & efforts for data prep

Save time & efforts for data prep

Resources

Stay always up to date on data activation

Get access to tips and tricks to model your data

Discover our always evolving and regularly updated documentation

Find out how we keep your data safe