Sample Header Ad - 728x90

How to handle table that has an id which references multiple dimension tables?

0 votes
0 answers
221 views
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!
Asked by danieltisdale (1 rep)
Mar 2, 2020, 07:37 PM
Last activity: Mar 2, 2020, 08:58 PM