How do I populate a fact table from more than one table

320 Views Asked by At

I am doing a school assignment but I do not know how to populate a fact table. My query to do it is

Select CustomerID from dim_cust
Select ProductID from dim_product
select InvoiceID from dim_invoice

insert into [dim_fact] ([CustomerID], [ProductID], [InvoiceID]);

The dim_* are all tables that I filled in manually.

I get also get an "Incorrect syntax near ')'" error. I also have a column that will have the total number of invoices in the fact table (dim_fact).

Any help is greatly appreciated, thank you!

Code

Product Table

Invoice Table

Customer Table

fact table

1

There are 1 best solutions below

0
On

I assume that invoice table has both customerid and productid information. So you can join dim_cust and dim_invoice table to get what you want.

insert into [dim_fact] 
select c.[CustomerID], i.[ProductID], i.[InvoiceID]
from dim_cust c inner join dim_invoice i on c.customerid=i.customerid;