DronaBlog

Tuesday, January 19, 2021

Join Conditions in Snowflake

 Are you looking for an article about the type of Join conditions in Snowflake? Are you also would like to understand these different types of join conditions in detail? If so, then you reached the right place. In this article, we will understand various join conditions used in Snowflake.





Introduction:

As like DBMS, Snowflake supports various types of join conditions. Join condition allow us to combine data from two or more tables. In Snowflake, there is no association between the tables using the primary key and foreign keys but we can still use the join condition.


Type of Join in Snowflake:

  • Inner Join
  • Outer Join
    • Left Outer Join
    • Right Outer Join
    • Full Outer Join
Let's understand each Type of Join with help of the Venn diagram

Understanding Syntax for Join Condition

Using the join condition in the SELECT statement is command practice. After writing the SELECT statement in the FROM clause we need to provide a table name then followed by the JOIN keyword. We also need to provide details on which column we need to perform join by using an ON clause. Here is the syntax for the join condition in Snowflake.




A. Inner Join

The Inner join in Snowflake is used to return rows from both tables which satisfy the condition. 

Example:
SELECT CUST.CUST_NBR
, CUST.FIRST_NAME
, CUST.LAST_NAME
, ADDR.AD_LINE_1
, ADDR.COUNTRY
FROM CUSTOMER CUST
INNER JOIN ADDRESS ADDR
ON CUST.CUST_NBR = ADDR.CUST_NBR.

The above query returns the elements which common between the CUSTOMER and ADDRESS tables.


B. Outer Join

If two tables do not contain all the records then we use an OUTER JOIN. Each table contains records even if the other table does not contain any corresponding record. The outer Join is subcategorized as 
  1. Left Outer Join
  2. Right Outer Join
  3. Full Outer Join
Let's understand these Outer join one by one.

1. Left Outer Join

The LEFT JOIN in Snowflake returns all the rows from the table on the left side of the equation even if there are no matching rows in the table on the right side of the equation.



Syntax

SELECT CUST.CUST_NBR
, CUST.FIRST_NAME
, CUST.LAST_NAME
, ADDR.AD_LINE_1
, ADDR.COUNTRY
FROM CUSTOMER CUST
LEFT OUTER JOIN ADDRESS ADDR
ON CUST.CUST_NBR = ADDR.CUST_NBR.





2. Right Outer Join


The RIGHT JOIN in Snowflake returns all the rows from the table on the right side of the equation even if there are no matching rows in the table on the left side of the equation
.
Syntax
SELECT CUST.CUST_NBR
, CUST.FIRST_NAME
, CUST.LAST_NAME
, ADDR.AD_LINE_1
, ADDR.COUNTRY
FROM CUSTOMER CUST
RIGHT OUTER JOIN ADDRESS ADDR
ON CUST.CUST_NBR = ADDR.CUST_NBR.

3. Full Outer Join

The FULL OUTER JOIN in Snowflake returns all the rows from both tables irrespective of condition match.
Syntax
SELECT CUST.CUST_NBR
, CUST.FIRST_NAME
, CUST.LAST_NAME
, ADDR.AD_LINE_1
, ADDR.COUNTRY
FROM CUSTOMER CUST
FULL OUTER JOIN ADDRESS ADDR
ON CUST.CUST_NBR = ADDR.CUST_NBR.


















Learn more about Snowflake here

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Understanding Survivorship in Informatica IDMC - Customer 360 SaaS

  In Informatica IDMC - Customer 360 SaaS, survivorship is a critical concept that determines which data from multiple sources should be ret...