Iqra Qureshi - 1 year ago 44

SQL Question

I have two tables in SQL named

`tblFolding`

`tblStockManagement`

`tblFolding`

`FoldingID`

`Price`

`tblStockManagement`

`FoldingID`

`tblFolding`

`Quantity`

All I want is calculate the

`Total Price`

`tblStockManagement`

`Price`

`tblFolding`

Answer

This will provide total price by folding id wise

```
SELECT TF.FoldingID, SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
GROUP BY TF.FoldingID
```

If don't want to get the result by foldingid wise and expect the whole total price, try this:

```
SELECT SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
```

**UPDATE:**

From your comments, what I understand is you want results according to `FoldingID`

in `tblStockManagement`

table. So add the WHERE clause and filter by the condition.

```
SELECT TF.FoldingID, SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
WHERE SM.FoldingID IN (1, 2, 3, 4) -- modify the condition as per your requirement
GROUP BY TF.FoldingID
```

Source (Stackoverflow)