SQL to List All Categories and Products (SKUs) in Category in Magento 1.9

databasemagento-1.9sql

guys !
How can i list all categories with related products in them (i need the SKUs). Where is the relation table for catalog_category_entity(or varchar) and catalog_product_entity(or varchar). ?

I can use only SQL.. because i don't know php. Thx !

Best Answer

The category product relation table is catalog_category_product. It contains the category id and the product id its related to. Also there is the position column position which determines the order in which the products are fetched.

So to get the product SKU you need do a join with the catalog_product_entity which has the SKU's for the products.

So something like

SELECT
    * 
FROM
    `catalog_category_product` `ccp` 
JOIN
    `catalog_product_entity` as `cpe` 
        ON `cpe`.entity_id = `ccp`.`product_id`

should help you get the SKU's against the product ids. And of course you can replace the SELECT * with only the fields you like to have.

Hope this helps !!