How to Join a Fact Table to Junk Dimension

310 Views Asked by At

If I have a fact table and want to join it to a Junk Dimension table to hold the various combinations of attributes for a fact how do I join this in SQL in the underlying ETL efficiently after creating the Dim table?

Do I simply have to join the Fact Table source data to the Dim Junk on the various columns that exist in the Junk? What if there are 10+? Will this just be a case of 10+ joins?

EDIT: Added schema and explanation below

Example Schema below

Fact Action Table

  • Date
  • Action Key
  • Dim Junk Key
  • Case # (Degenerate Dimension)

Dim Junk Case

  • Key
  • Status
  • Manager
  • Source

When creating the SQL to generate the Fact Table from its source data I need to choose a key from the junk case dimension. Would this be done by joining the Fact Source data to the Junk table via the Case?

I imagine the SQL would be like:

SELECT column1, column2, column3, JC.[Junk Surrogate Key],     
FROM FactSource FS    
  LEFT JOIN CASESOURCEDATA CS ON FS.Case# = CS.Case#    
  LEFT JOIN DimJunkCase JC 
    ON 
      JC.column1 = CS.column1 AND    
      JC.column2 = CS.column2 AND    
      JC.column3 = CS.column3 AND    
      JC.column4 = CS.column4
1

There are 1 best solutions below

1
Chaddeus On

Answered in comments. Initial SQL was correct. Multiple Joins must be used to join fact to junk dimension