Guides › Database reference › Orders and sales
Magento 2 sales_order table
One row per order: its number, state and status, customer, store view, totals and currencies. Every other sales table points back to it.
Key columns
| Column | What it means |
|---|---|
entity_id | Internal order ID. Other sales tables link to it, e.g. sales_order_item.order_id. |
increment_id | The order number shown in the admin and in emails, such as 000000123. |
state | Magento's fixed workflow stage: new, pending_payment, processing, complete, closed, canceled, holded or payment_review. |
status | The status code shown to people. Each state can have several statuses, including your own custom ones. |
store_id | The store view the order was placed in. |
customer_id | The customer account, or NULL for guest orders (then customer_is_guest is 1). |
grand_total / base_grand_total | The order total in the order's currency / in your base currency. |
discount_amount | The order's discount, stored as a negative number. |
created_at | When the order was placed, stored in UTC. |
Good to know
- Columns starting with
base_are in your base currency; the others are in the currency the customer paid in. - "On Hold" is stored as
holded. Query status codes, not the labels you see in the admin. - On Adobe Commerce this table has many more columns, for gift cards, store credit, reward points and gift wrapping (full list below).
Example: Orders and revenue per status, last 30 days
Works on Magento Open Source and Adobe Commerce.
SELECT status, COUNT(*) AS orders, ROUND(SUM(base_grand_total), 2) AS revenue
FROM sales_order
WHERE created_at >= NOW() - INTERVAL 30 DAY
GROUP BY status
ORDER BY orders DESC;
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 207 columns here instead of 139. The extra ones come from these Commerce features:
- Customer Balance:
base_customer_balance_amount,customer_balance_amount,base_customer_balance_invoiced,customer_balance_invoiced,base_customer_balance_refunded,customer_balance_refunded,bs_customer_bal_total_refunded,customer_bal_total_refunded - Gift Card Account:
gift_cards,base_gift_cards_amount,gift_cards_amount,base_gift_cards_invoiced,gift_cards_invoiced,base_gift_cards_refunded,gift_cards_refunded - Gift Wrapping:
gw_id,gw_allow_gift_receipt,gw_add_card,gw_base_price,gw_price,gw_items_base_price,gw_items_price,gw_card_base_price,gw_card_price,gw_base_tax_amount,gw_tax_amount,gw_items_base_tax_amount,gw_items_tax_amount,gw_card_base_tax_amount,gw_card_tax_amount,gw_base_price_incl_tax,gw_price_incl_tax,gw_items_base_price_incl_tax,gw_items_price_incl_tax,gw_card_base_price_incl_tax,gw_card_price_incl_tax,gw_base_price_invoiced,gw_price_invoiced,gw_items_base_price_invoiced,gw_items_price_invoiced,gw_card_base_price_invoiced,gw_card_price_invoiced,gw_base_tax_amount_invoiced,gw_tax_amount_invoiced,gw_items_base_tax_invoiced,gw_items_tax_invoiced,gw_card_base_tax_invoiced,gw_card_tax_invoiced,gw_base_price_refunded,gw_price_refunded,gw_items_base_price_refunded,gw_items_price_refunded,gw_card_base_price_refunded,gw_card_price_refunded,gw_base_tax_amount_refunded,gw_tax_amount_refunded,gw_items_base_tax_refunded,gw_items_tax_refunded,gw_card_base_tax_refunded,gw_card_tax_refunded - Reward:
reward_points_balance,base_reward_currency_amount,reward_currency_amount,base_rwrd_crrncy_amt_invoiced,rwrd_currency_amount_invoiced,base_rwrd_crrncy_amnt_refnded,rwrd_crrncy_amnt_refunded,reward_points_balance_refund
Foreign keys
customer_id→ customer_entity.entity_idstore_id→store.store_id
All 139 columns (Magento Open Source)
Show all columns
| Column | Type | Can be empty | Magento's description |
|---|---|---|---|
entity_id | int(10) unsigned | Entity ID | |
state | varchar(32) | yes | State |
status | varchar(32) | yes | Status |
coupon_code | varchar(255) | yes | Coupon Code |
protect_code | varchar(255) | yes | Protect Code |
shipping_description | varchar(255) | yes | Shipping Description |
is_virtual | smallint(5) unsigned | yes | Is Virtual |
store_id | smallint(5) unsigned | yes | Store ID |
customer_id | int(10) unsigned | yes | Customer ID |
base_discount_amount | decimal(20,4) | yes | Base Discount Amount |
base_discount_canceled | decimal(20,4) | yes | Base Discount Canceled |
base_discount_invoiced | decimal(20,4) | yes | Base Discount Invoiced |
base_discount_refunded | decimal(20,4) | yes | Base Discount Refunded |
base_grand_total | decimal(20,4) | yes | Base Grand Total |
base_shipping_amount | decimal(20,4) | yes | Base Shipping Amount |
base_shipping_canceled | decimal(20,4) | yes | Base Shipping Canceled |
base_shipping_invoiced | decimal(20,4) | yes | Base Shipping Invoiced |
base_shipping_refunded | decimal(20,4) | yes | Base Shipping Refunded |
base_shipping_tax_amount | decimal(20,4) | yes | Base Shipping Tax Amount |
base_shipping_tax_refunded | decimal(20,4) | yes | Base Shipping Tax Refunded |
base_subtotal | decimal(20,4) | yes | Base Subtotal |
base_subtotal_canceled | decimal(20,4) | yes | Base Subtotal Canceled |
base_subtotal_invoiced | decimal(20,4) | yes | Base Subtotal Invoiced |
base_subtotal_refunded | decimal(20,4) | yes | Base Subtotal Refunded |
base_tax_amount | decimal(20,4) | yes | Base Tax Amount |
base_tax_canceled | decimal(20,4) | yes | Base Tax Canceled |
base_tax_invoiced | decimal(20,4) | yes | Base Tax Invoiced |
base_tax_refunded | decimal(20,4) | yes | Base Tax Refunded |
base_to_global_rate | decimal(20,4) | yes | Base To Global Rate |
base_to_order_rate | decimal(20,4) | yes | Base To Order Rate |
base_total_canceled | decimal(20,4) | yes | Base Total Canceled |
base_total_invoiced | decimal(20,4) | yes | Base Total Invoiced |
base_total_invoiced_cost | decimal(20,4) | yes | Base Total Invoiced Cost |
base_total_offline_refunded | decimal(20,4) | yes | Base Total Offline Refunded |
base_total_online_refunded | decimal(20,4) | yes | Base Total Online Refunded |
base_total_paid | decimal(20,4) | yes | Base Total Paid |
base_total_qty_ordered | decimal(12,4) | yes | Base Total Qty Ordered |
base_total_refunded | decimal(20,4) | yes | Base Total Refunded |
discount_amount | decimal(20,4) | yes | Discount Amount |
discount_canceled | decimal(20,4) | yes | Discount Canceled |
discount_invoiced | decimal(20,4) | yes | Discount Invoiced |
discount_refunded | decimal(20,4) | yes | Discount Refunded |
grand_total | decimal(20,4) | yes | Grand Total |
shipping_amount | decimal(20,4) | yes | Shipping Amount |
shipping_canceled | decimal(20,4) | yes | Shipping Canceled |
shipping_invoiced | decimal(20,4) | yes | Shipping Invoiced |
shipping_refunded | decimal(20,4) | yes | Shipping Refunded |
shipping_tax_amount | decimal(20,4) | yes | Shipping Tax Amount |
shipping_tax_refunded | decimal(20,4) | yes | Shipping Tax Refunded |
store_to_base_rate | decimal(12,4) | yes | Store To Base Rate |
store_to_order_rate | decimal(12,4) | yes | Store To Order Rate |
subtotal | decimal(20,4) | yes | Subtotal |
subtotal_canceled | decimal(20,4) | yes | Subtotal Canceled |
subtotal_invoiced | decimal(20,4) | yes | Subtotal Invoiced |
subtotal_refunded | decimal(20,4) | yes | Subtotal Refunded |
tax_amount | decimal(20,4) | yes | Tax Amount |
tax_canceled | decimal(20,4) | yes | Tax Canceled |
tax_invoiced | decimal(20,4) | yes | Tax Invoiced |
tax_refunded | decimal(20,4) | yes | Tax Refunded |
total_canceled | decimal(20,4) | yes | Total Canceled |
total_invoiced | decimal(20,4) | yes | Total Invoiced |
total_offline_refunded | decimal(20,4) | yes | Total Offline Refunded |
total_online_refunded | decimal(20,4) | yes | Total Online Refunded |
total_paid | decimal(20,4) | yes | Total Paid |
total_qty_ordered | decimal(12,4) | yes | Total Qty Ordered |
total_refunded | decimal(20,4) | yes | Total Refunded |
can_ship_partially | smallint(5) unsigned | yes | Can Ship Partially |
can_ship_partially_item | smallint(5) unsigned | yes | Can Ship Partially Item |
customer_is_guest | smallint(5) unsigned | yes | Customer Is Guest |
customer_note_notify | smallint(5) unsigned | yes | Customer Note Notify |
billing_address_id | int(11) | yes | Billing Address ID |
customer_group_id | int(11) | yes | |
edit_increment | int(11) | yes | Edit Increment |
email_sent | smallint(5) unsigned | yes | Email Sent |
send_email | smallint(5) unsigned | yes | Send Email |
forced_shipment_with_invoice | smallint(5) unsigned | yes | Forced Do Shipment With Invoice |
payment_auth_expiration | int(11) | yes | Payment Authorization Expiration |
quote_address_id | int(11) | yes | Quote Address ID |
quote_id | int(11) | yes | Quote ID |
shipping_address_id | int(11) | yes | Shipping Address ID |
adjustment_negative | decimal(20,4) | yes | Adjustment Negative |
adjustment_positive | decimal(20,4) | yes | Adjustment Positive |
base_adjustment_negative | decimal(20,4) | yes | Base Adjustment Negative |
base_adjustment_positive | decimal(20,4) | yes | Base Adjustment Positive |
base_shipping_discount_amount | decimal(20,4) | yes | Base Shipping Discount Amount |
base_subtotal_incl_tax | decimal(20,4) | yes | Base Subtotal Incl Tax |
base_total_due | decimal(20,4) | yes | Base Total Due |
payment_authorization_amount | decimal(20,4) | yes | Payment Authorization Amount |
shipping_discount_amount | decimal(20,4) | yes | Shipping Discount Amount |
subtotal_incl_tax | decimal(20,4) | yes | Subtotal Incl Tax |
total_due | decimal(20,4) | yes | Total Due |
weight | decimal(12,4) | yes | Weight |
customer_dob | datetime | yes | Customer Dob |
increment_id | varchar(50) | yes | Increment ID |
applied_rule_ids | varchar(128) | yes | Applied Rule Ids |
base_currency_code | varchar(3) | yes | Base Currency Code |
customer_email | varchar(128) | yes | Customer Email |
customer_firstname | varchar(128) | yes | Customer Firstname |
customer_lastname | varchar(128) | yes | Customer Lastname |
customer_middlename | varchar(128) | yes | Customer Middlename |
customer_prefix | varchar(32) | yes | Customer Prefix |
customer_suffix | varchar(32) | yes | Customer Suffix |
customer_taxvat | varchar(32) | yes | Customer Taxvat |
discount_description | varchar(255) | yes | Discount Description |
ext_customer_id | varchar(32) | yes | Ext Customer ID |
ext_order_id | varchar(32) | yes | Ext Order ID |
global_currency_code | varchar(3) | yes | Global Currency Code |
hold_before_state | varchar(32) | yes | Hold Before State |
hold_before_status | varchar(32) | yes | Hold Before Status |
order_currency_code | varchar(3) | yes | Order Currency Code |
original_increment_id | varchar(50) | yes | Original Increment ID |
relation_child_id | varchar(32) | yes | Relation Child ID |
relation_child_real_id | varchar(32) | yes | Relation Child Real ID |
relation_parent_id | varchar(32) | yes | Relation Parent ID |
relation_parent_real_id | varchar(32) | yes | Relation Parent Real ID |
remote_ip | varchar(45) | yes | Remote Ip |
shipping_method | varchar(120) | yes | |
store_currency_code | varchar(3) | yes | Store Currency Code |
store_name | varchar(255) | yes | Store Name |
x_forwarded_for | varchar(255) | yes | X Forwarded For |
customer_note | text | yes | Customer Note |
created_at | timestamp | Created At | |
updated_at | timestamp | Updated At | |
total_item_count | smallint(5) unsigned | Total Item Count | |
customer_gender | int(11) | yes | Customer Gender |
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 |
shipping_discount_tax_compensation_amount | decimal(20,4) | yes | Shipping Discount Tax Compensation Amount |
base_shipping_discount_tax_compensation_amnt | decimal(20,4) | yes | Base Shipping 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 |
shipping_incl_tax | decimal(20,4) | yes | Shipping Incl Tax |
base_shipping_incl_tax | decimal(20,4) | yes | Base Shipping Incl Tax |
coupon_rule_name | varchar(255) | yes | Coupon Sales Rule Name |
gift_message_id | int(11) | yes | Gift Message ID |
paypal_ipn_customer_notified | int(11) | yes | Paypal Ipn Customer Notified |
dispute_status | varchar(45) | yes | Braintree Dispute Status |