From a SQL Query I need to know how does magento key the related products to the actual product itself. I read a lot of useful tips on how to do with with php
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSort('name', 'ASC');
But I need to know how to identity these groups to a id with mysql.
For a related product Magento uses catalog_product_link
table.
In it you have product id, related product and link type.
To see all link types you can check the catalog_product_link_type
table.
SELECT link.link_id, link.product_id, link.linked_product_id, link.link_type_id, type.code
FROM catalog_product_link link
LEFT JOIN catalog_product_link_type type ON link.link_type_id = type.link_type_id
WHERE
code = 'super' -- grouped products
AND linked_product_id IN (123456) -- child simple product(s)
;
More extensive information can be found with this link:
online Database Diagram Tool dedicated to Magento eCommerce CE Edition