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
| Column | What it means |
|---|---|
category_id | The category, linking to catalog_category_entity.entity_id. |
product_id | The product's ID (entity_id, on Adobe Commerce too). |
position | Sort order of the product in that category. |
Good to know
- This table holds only direct assignments. Anchor categories also show products from their subcategories, through the storefront index tables.
- After changing it directly, reindex, or the storefront won't change.
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
product_id→ catalog_product_entity.entity_idcategory_id→catalog_category_entity.entity_idproduct_id→sequence_product.sequence_valueAdobe Commercecategory_id→sequence_catalog_category.sequence_valueAdobe Commerce
All 4 columns (Magento Open Source)
Show all columns
| Column | Type | Can be empty | Magento's description |
|---|---|---|---|
entity_id | int(11) | Entity ID | |
category_id | int(10) unsigned | Category ID | |
product_id | int(10) unsigned | Product ID | |
position | int(11) | Position |