Guides › Database reference › Orders and sales
Magento 2 sales_order_item table
One row per product line in an order. Configurable and bundle products have a parent row plus child rows, so the same sale can appear twice.
Key columns
| Column | What it means |
|---|---|
item_id | Internal ID of the order line. |
order_id | The order, linking to sales_order.entity_id. |
parent_item_id | NULL for a top-level line. For the chosen variant of a configurable product (or a bundle part), the parent line's item_id. |
product_id | The product's ID at the time of ordering. On the parent line of a configurable product, it's the configurable product. |
sku / name | Copied at order time. On the parent line of a configurable product, sku is the chosen variant's SKU. |
product_type | simple, configurable, bundle, virtual and so on. |
qty_ordered | Quantity ordered. Also qty_invoiced, qty_shipped, qty_refunded and qty_canceled. |
price / row_total | Unit price and price × quantity, before discount and without tax. base_ versions are in your base currency. |
discount_amount | The line's discount, stored as a positive number (unlike sales_order). |
Good to know
- To count a sale once, use only top-level lines:
parent_item_id IS NULL. - For configurable products, the child (variant) line has a price of 0. The price is on the parent line.
- Order lines keep the SKU and name from the time of the order, even if the product is renamed or deleted later.
Example: Top 10 products by quantity sold, last 30 days
Works on Magento Open Source and Adobe Commerce.
SELECT i.sku, MAX(i.name) AS name, SUM(i.qty_ordered) AS qty, ROUND(SUM(i.base_row_total), 2) AS revenue
FROM sales_order_item i
JOIN sales_order o ON o.entity_id = i.order_id
WHERE o.created_at >= NOW() - INTERVAL 30 DAY
AND o.state NOT IN ('canceled', 'closed')
AND i.parent_item_id IS NULL -- one row per product line
GROUP BY i.sku
ORDER BY qty DESC
LIMIT 10;
Tested on Magento Open Source and Adobe Commerce 2.4.8. Read-only. If your tables have a prefix, add it to each table name.
Extra columns on Adobe Commerce
Adobe Commerce has 96 columns here instead of 80. The extra ones come from these Commerce features:
- Catalog Event:
event_id - Gift Registry:
giftregistry_item_id - Gift Wrapping:
gw_id,gw_base_price,gw_price,gw_base_tax_amount,gw_tax_amount,gw_base_price_invoiced,gw_price_invoiced,gw_base_tax_amount_invoiced,gw_tax_amount_invoiced,gw_base_price_refunded,gw_price_refunded,gw_base_tax_amount_refunded,gw_tax_amount_refunded - Rma:
qty_returned
Foreign keys
order_id→ sales_order.entity_idstore_id→store.store_id
All 80 columns (Magento Open Source)
Show all columns
| Column | Type | Can be empty | Magento's description |
|---|---|---|---|
item_id | int(10) unsigned | Item ID | |
order_id | int(10) unsigned | Order ID | |
parent_item_id | int(10) unsigned | yes | Parent Item ID |
quote_item_id | int(10) unsigned | yes | Quote Item ID |
store_id | smallint(5) unsigned | yes | Store ID |
created_at | timestamp | Created At | |
updated_at | timestamp | Updated At | |
product_id | int(10) unsigned | yes | Product ID |
product_type | varchar(255) | yes | Product Type |
product_options | longtext | yes | Product Options |
weight | decimal(12,4) | yes | Weight |
is_virtual | smallint(5) unsigned | yes | Is Virtual |
sku | varchar(255) | yes | Sku |
name | varchar(255) | yes | Name |
description | text | yes | Description |
applied_rule_ids | text | yes | Applied Rule Ids |
additional_data | text | yes | Additional Data |
is_qty_decimal | smallint(5) unsigned | yes | Is Qty Decimal |
no_discount | smallint(5) unsigned | No Discount | |
qty_backordered | decimal(12,4) | yes | Qty Backordered |
qty_canceled | decimal(12,4) | yes | Qty Canceled |
qty_invoiced | decimal(12,4) | yes | Qty Invoiced |
qty_ordered | decimal(12,4) | yes | Qty Ordered |
qty_refunded | decimal(12,4) | yes | Qty Refunded |
qty_shipped | decimal(12,4) | yes | Qty Shipped |
base_cost | decimal(12,4) | yes | Base Cost |
price | decimal(20,4) | Price | |
base_price | decimal(20,4) | Base Price | |
original_price | decimal(20,4) | yes | Original Price |
base_original_price | decimal(20,4) | yes | Base Original Price |
tax_percent | decimal(12,4) | yes | Tax Percent |
tax_amount | decimal(20,4) | yes | Tax Amount |
base_tax_amount | decimal(20,4) | yes | Base Tax Amount |
tax_invoiced | decimal(20,4) | yes | Tax Invoiced |
base_tax_invoiced | decimal(20,4) | yes | Base Tax Invoiced |
discount_percent | decimal(12,4) | yes | Discount Percent |
discount_amount | decimal(20,4) | yes | Discount Amount |
base_discount_amount | decimal(20,4) | yes | Base Discount Amount |
discount_invoiced | decimal(20,4) | yes | Discount Invoiced |
base_discount_invoiced | decimal(20,4) | yes | Base Discount Invoiced |
amount_refunded | decimal(20,4) | yes | Amount Refunded |
base_amount_refunded | decimal(20,4) | yes | Base Amount Refunded |
row_total | decimal(20,4) | Row Total | |
base_row_total | decimal(20,4) | Base Row Total | |
row_invoiced | decimal(20,4) | Row Invoiced | |
base_row_invoiced | decimal(20,4) | Base Row Invoiced | |
row_weight | decimal(12,4) | yes | Row Weight |
base_tax_before_discount | decimal(20,4) | yes | Base Tax Before Discount |
tax_before_discount | decimal(20,4) | yes | Tax Before Discount |
ext_order_item_id | varchar(255) | yes | Ext Order Item ID |
locked_do_invoice | smallint(5) unsigned | yes | Locked Do Invoice |
locked_do_ship | smallint(5) unsigned | yes | Locked Do Ship |
price_incl_tax | decimal(20,4) | yes | Price Incl Tax |
base_price_incl_tax | decimal(20,4) | yes | Base Price Incl Tax |
row_total_incl_tax | decimal(20,4) | yes | Row Total Incl Tax |
base_row_total_incl_tax | decimal(20,4) | yes | Base Row Total Incl Tax |
discount_tax_compensation_amount | decimal(20,4) | yes | Discount Tax Compensation Amount |
base_discount_tax_compensation_amount | decimal(20,4) | yes | Base Discount Tax Compensation Amount |
discount_tax_compensation_invoiced | decimal(20,4) | yes | Discount Tax Compensation Invoiced |
base_discount_tax_compensation_invoiced | decimal(20,4) | yes | Base Discount Tax Compensation Invoiced |
discount_tax_compensation_refunded | decimal(20,4) | yes | Discount Tax Compensation Refunded |
base_discount_tax_compensation_refunded | decimal(20,4) | yes | Base Discount Tax Compensation Refunded |
tax_canceled | decimal(12,4) | yes | Tax Canceled |
discount_tax_compensation_canceled | decimal(20,4) | yes | Discount Tax Compensation Canceled |
tax_refunded | decimal(20,4) | yes | Tax Refunded |
base_tax_refunded | decimal(20,4) | yes | Base Tax Refunded |
discount_refunded | decimal(20,4) | yes | Discount Refunded |
base_discount_refunded | decimal(20,4) | yes | Base Discount Refunded |
weee_tax_applied | text | yes | Weee Tax Applied |
weee_tax_applied_amount | decimal(12,4) | yes | Weee Tax Applied Amount |
weee_tax_applied_row_amount | decimal(12,4) | yes | Weee Tax Applied Row Amount |
weee_tax_disposition | decimal(12,4) | yes | Weee Tax Disposition |
weee_tax_row_disposition | decimal(12,4) | yes | Weee Tax Row Disposition |
base_weee_tax_applied_amount | decimal(12,4) | yes | Base Weee Tax Applied Amount |
base_weee_tax_applied_row_amnt | decimal(12,4) | yes | Base Weee Tax Applied Row Amnt |
base_weee_tax_disposition | decimal(12,4) | yes | Base Weee Tax Disposition |
base_weee_tax_row_disposition | decimal(12,4) | yes | Base Weee Tax Row Disposition |
gift_message_id | int(11) | yes | Gift Message ID |
gift_message_available | int(11) | yes | Gift Message Available |
free_shipping | smallint(5) unsigned | Free Shipping |