Question: I have a sample db with 3 different tables, `customers`, `orders`, `orderdetails`.

The assignment is to show customer name, and address from a customers table and then show each order total amount by order id. Order details has order id several times and it is by unit x price so I have to sum these after performing the calculation.

Customers has a field customerid, which I can use to join with orders which has the same field, the orders table has orderid which I can use to join to orderdetails and sum the order total but I do not know how to put the information together. Customers table does not have the fields to calculate the total order, and only has customerid. So, I'm trying to pinch together from 3 tables where there is some related column but not all present in each table.

I can do 2 separate select statements and each do what I expect but I have been trying to get the info together and have been unable to.

```
  SELECT c.CustomerID, c.[Address], o.orderid
  FROM Customers c
  Join Orders o
  ON c.CustomerID = o.CustomerID

  --how to join these together?

  SELECT od.orderid, SUM(od.UnitPrice*od.Quantity) as 'Subtotal'
  FROM OrderDetails od
  Join Orders o
  ON od.OrderID = o.OrderID
  Group by od.OrderID

```

I am trying to show this with the following information:

```
Customer Name, Address, OrderID, and Order Total.

```

Answer: 
try this -

```
 SELECT c.CustomerID, c.[Address], od.orderid, SUM(od.UnitPrice* od.Quantity) as 'Subtotal'
  FROM OrderDetails od
  Join Orders o
  ON od.OrderID = o.OrderID
  join Customers c  ON c.CustomerID = o.CustomerID
  Group by c.CustomerID,  c.[Address], od.OrderID

```
Mukesh's answer led me directly to the finish, I was able to leave the customerid out of the result with the following. This helped a lot and I appreciate everyone's input.

```
  SELECT c.CompanyName, c.[Address], od.orderid, SUM(od.UnitPrice* od.Quantity) as
  'Subtotal'
  FROM OrderDetails od
  Join Orders o
  ON od.OrderID = o.OrderID
  join Customers c  ON c.CustomerID = o.CustomerID
  Group by c.CompanyName,  c.[Address], od.OrderID

```