SFMC SQL - JOINS

 Naveen_SFMC_SQL_Joins

 -:JOINS:-

-:JOIN in Salesforce Marketing Cloud:-

In SFMC, A JOIN is used to combine data from multiple Data Extensions (tables) using a common field.

In Salesforce Marketing Cloud, data is usually stored in multiple Data Extensions (DEs) instead of one single table.

JOINs are important because they help combine related data from different DEs using a common field.


Why JOINs Are Important


Without JOINs:👉

  1. data remains separated
  2. reports become difficult
  3. personalization is limited
  4. segmentation becomes hard

JOINs help marketers connect subscriber data, order data, journey data, and engagement data together.

First of all we created Three Source tables and one Target Table 

1. Naveen_Customer_table_Joins



2. Naveen_Order_table_Joins




3. Naveen_self_Join




4. Naveen_Customer_Table_Joins_TargetDE


-----------------------------------------------------------------------------------------------------------------------------

1. Inner Join :- 

INNER JOIN returns only the rows that have matching values in both tables

Query:- 

Select

CDE.Customer_ID, CDE.Name, CDE.City, ODE.Product

from Naveen_Customer_table_Joins CDE

inner join Naveen_Order_table_Joins ODE

on CDE.Customer_ID = ODE.Customer_ID








Result : Inner Join only return common or matching data from both the table.




2.  Left Join :-

LEFT JOIN returns:👉

  • All records from the left table
  • Matching records from the right table

If no match exists, NULL values are returned from the right table.

In SFMC :  

LEFT JOIN shows all data from the left Data Extension and matching data from the right Data Extension.

Query:- 

Select

CDE.Customer_ID, CDE.Name, CDE.City, ODE.Product

from Naveen_Customer_table_Joins CDE

Left join Naveen_Order_table_Joins ODE

on CDE.Customer_ID = ODE.Customer_ID 








Result :      In result, all the left Table data is fetched and only matching data from right table fetch, Where data is not available for particular Customer_ID - data is null. 



3. Right Join

RIGHT JOIN returns:👉
  • all records from the right table
  • matching records from the left table
If no match exists, NULL values are returned from the left table. 

In SFMC: 

RIGHT JOIN shows all data from the right Data Extension and matching data from the left Data Extension.

Query:-

Select

ODE.Customer_ID, CDE.Name, CDE.City, ODE.Product
from Naveen_Customer_table_Joins CDE
Right join Naveen_Order_table_Joins ODE
on ODE.Customer_ID = CDE.Customer_ID 






 


 

 





Comments

Popular posts from this blog

Data filter