0

I'm having a hard time figuring out how to create a lookup table or a table that references multiple dimension tables. I've got a "tracking" table that tracks the number of impressions for an e-commerce website. Each type of impression: manufacturer, product, evaluation is contained is a single objectid column, which references the corresponding dimension table for either manufacturer, product, or evaluation.

What I am struggling with is:

  • manufacturer impressions = manufacturer + product + evaluation impressions
  • product impressions = product + evaluation impressions

I need to be able to query all of the manufacturer impressions, which is a combination of the 3 types of impressions above. If I just query those that match on manufacturer, I will be leaving out the impressions that match on product and/or evaluation. The same thing goes for product impressions.

What is the best way to create a reference table or to be able to query all manufacturer impressions? I need to be able to write a query that combines objectid = manufacturerid + objectid = productid (which has a corresponding manufacturerid) + objectid = evaluationid (which has a corresponding productid and then a corresponding manufacturerid that links to the productid).

Here's a sample query I'm using, but it's not returning any rows when I add in the second join statement:

select * from tracking t left join products p on t.objectid = p.productid and t.objecttype = 'Products' left join evaluations e on t."ObjectID" = e."ProductEvaluationID" and t.[ObjectType] = 'Evaluations' left join manufacturers m on t.objectid = m.manufacturerid and t.objecttype='Manufacturers' 

Any advice is greatly appreciated, thanks!

2
  • Here's a sample query that I have been trying to use, but it is not returning any rows: select * from tracking t left join products p on t.objectid = p.productid and t.objecttype = 'Products' left join evaluations e on t."ObjectID" = e."ProductEvaluationID" and t.[ObjectType] = 'Evaluations' left join manufacturers m on t.objectid = m.manufacturerid and t.objecttype='Manufacturers' Commented Mar 2, 2020 at 20:57
  • Please consider reading this advice. Generally, you'll need a union of joins with different object types. Alternatively, if tracking.objectid is unique, you can dispense with checking what objecttypes they are when joining. Commented Mar 2, 2020 at 21:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.