Question: So I have the following 3 tables:

```
Table: Products
Columns: id, name, description, price, currency

Table: Orders
Columns: id, firstName, lastName, phoneNumber

Table: Order_Products
Columns: orderId, productId, quantity

```

Now I'm trying to figure out where to put the total price of the order and I have 2 ideas:

1. Add a `totalPrice` column to the `Orders` table that will contain the sum of the `price * quantity` of all products in the order, or:
2. Add a `price` column to the `Order_Products` table that will contain the the `price * quantity` of that specific product, and then I'd have to get all `Order_Products` records for that order and sum their `price` columns.

I'm not quite sure which option is better, hence why I'm asking for recommendations here.

Answer: 
I would recommend that you store the order total in the `orders` table.

Why? Basically, order totals are not necessarily the same as the sum of all the prices on the items:

* The prices might change over time.
* The order itself might have discounts.

In addition, the order might have additional charges:

* Discounts applied to the entire order.
* Taxes.
* Delivery charges.

For these reasons, I think it is safer to store financial information on the order when the order is placed.
I woulnd't recommend storing this. This is derived information, that can be computed on the fly whenever needed. If you are going to do the computation often, you can use a view:

```
create view orders_view as
select o.*, sum(p.price * op.quantity) total_price
from orders o
inner join order_products op on op.orderid = o.id
inner join products p on p.id = op.productid
group by o.id

```