How do I join these so as to get the amount with its product name?
SELECT [tblOrderDetails].[ProductId], sum(Ammount)
FROM [web].[dbo].[tblOrderDetails]
where [tblProducts].Id = [tblOrderDetails].ProductId
group by [tblOrderDetails].[ProductId]
SELECT [tblProducts].ProductName from [web].[dbo].[tblProducts]
Thanks,
Barry
If there is always going to be at least one entry in tblOrderDetails for each product then you can use the INNER JOIN:
What you are doing is saying for each Product in the Products table, give me the matching rows in the OrderDetails table that have the same Product.Id. You then group these by ProductName and SUM the amount to see the number per product.
If there is the possibility that there are no orders for a product, use a LEFT JOIN instead. This will return all rows in both tables that match, as well as any products that exist but do not have an entry in OrderDetails.
Jeff Atwood has a great visual explanation of what JOINS do over at Coding Horror: http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html