# Data in sql\_store::order\_items table

**URL:** <https://forum.codewithmosh.com/t/data-in-sql-store-order-items-table/24517>\
**Category:** SQL\
**Created:** [January 10, 2024, 1:00pm UTC](https://forum.codewithmosh.com/t/data-in-sql-store-order-items-table/24517 "2024-01-10T13:00:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adiv](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/adiv/32/7596_2.png) [@Adiv](https://forum.codewithmosh.com/u/Adiv)\
**Post date:** [January 10, 2024, 1:00pm UTC](https://forum.codewithmosh.com/t/data-in-sql-store-order-items-table/24517/1 "2024-01-10T13:00:53Z")

</div>

The data in the order\_items table in the sql\_store schema (database) seems inconsistent. In the first record for order\_id = 6, the product\_id is 1.

In the products table, the record where product\_id =1 is for item “Foam Dinner Plate”, with a unit\_price of 1.21.

But in the order\_items table, the unit\_price is 8.65. It should be the same value as in the products table, I believe.

Additionally, the unit\_price is an attribute of product and not an attribute of an order item, so it does not belong in the order\_items table, I believe.

Below is the SQL statement I wrote to return records from order\_items with the product name and the line total for each record where order\_id = 6.

```auto
SELECT 
    oi.order_id,
    p.name,
    p.unit_price,
    oi.quantity,
    p.unit_price * oi.quantity AS line_total
FROM
    order_items AS oi
        INNER JOIN
    products AS p ON oi.product_id = p.product_id
WHERE
    oi.order_id = 6;

```

 ![sql_store - order_items with line_total](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/5/5e9a92b89f93e43b356b94ce8206191580876611.jpeg)

Can you advise what I am failing to understand in this exercise?

Thank you kindly.

---

<div class="post-metadata">

**Author:** ![blitzmacht](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@blitzmacht](https://forum.codewithmosh.com/u/blitzmacht)\
**Post date:** [January 11, 2024, 1:48am UTC](https://forum.codewithmosh.com/t/data-in-sql-store-order-items-table/24517/2 "2024-01-11T01:48:32Z")

</div>

> [@Adiv](#):
>
> first record for order\_id = 6, the product\_id is 1.
> 
> In the products table, the record where product\_id =1 is for item “Foam Dinner Plate”, with a unit\_price of 1.21.
> 
> But in the order\_items table, the unit\_price is 8.65. It should be the same value as in the products table, I believe.
> 
> Additionally, the unit\_price is an attribute of product and not an attribute of an order item, so it does not belong in the order\_items table, I believe.
> 
> Below is the SQL statement I wrote to return records from order\_items with the product name and the line total for each record where order\_id = 6.

It’s been awhile since I completed the course, but I believe the products table shows the current unit\_price of the product, whereas the order\_items table shows the unit\_price of the product at the time the order was placed. A business may change the price of a product but the change wouldn’t reflect for orders already placed for that item.
