AI Reports

Guides › Database reference › Categories and stock

Magento 2 catalog_category_product table

Which products are in which categories, and their position in each.

Key columns

ColumnWhat it means
category_idThe category, linking to catalog_category_entity.entity_id.
product_idThe product's ID (entity_id, on Adobe Commerce too).
positionSort order of the product in that category.

Good to know

Example: Products that aren't in any category

Magento Open Source

SELECT e.sku, e.type_id
FROM catalog_product_entity e
LEFT JOIN catalog_category_product c ON c.product_id = e.entity_id
WHERE c.product_id IS NULL
ORDER BY e.sku;

Adobe Commerce

SELECT e.sku, e.type_id
FROM catalog_product_entity e
LEFT JOIN catalog_category_product c ON c.product_id = e.entity_id
WHERE c.product_id IS NULL
  AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
ORDER BY e.sku;

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.

This table has the same 4 columns on Magento Open Source and Adobe Commerce.

Foreign keys

All 4 columns (Magento Open Source)

Show all columns
ColumnTypeCan be emptyMagento's description
entity_idint(11)Entity ID
category_idint(10) unsignedCategory ID
product_idint(10) unsignedProduct ID
positionint(11)Position

Related tables

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn