Magento – Magento 2: Get Product URL and SKU using SQL Query
magento-2.1querysql
How can I get all SKUs and Product URLs using only SQL Query?
Best Answer
Magento does not save product URLs completely in database tables. It saves only URL key, so you can get SKU and URL key directly from tables.
SKU is saved in catalog_product_entity table.
By default product's URL key is an attribute which is of type varchar, so its value is saved in catalog_product_entity_varchar table. By default attribute id of product's URL key is 124.
Magento is saved Product price at catalog_product_index_price and
Here magento is saved customer group wise products price fields.So you need to inner join with this table.But is give you multiple rows for a products.By default it take one row when customer is not logged-in.
Product ID
Customer Group ID
Website ID
Tax Class ID
Price Final
Price Min
Price Max
Price Tier
Price Group price
See table:
Here the Query:
SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`,
`price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL,
LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS
`minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`,
`price_index`.`tier_price` FROM `catalog_product_entity` AS `e` INNER JOIN
`catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND
price_index.website_id = '0' AND price_index.customer_group_id = 0
Here i have put customer group id and its 0 for getting on a records product price
$parentSku = 'testSku';
SELECT t2.sku FROM
(SELECT b.child_id
FROM `catalog_product_entity` a
LEFT JOIN `catalog_product_relation` b
ON b.`parent_id` = a.`entity_id`
WHERE a.sku = '{$parentSku}') t1
LEFT JOIN catalog_product_entity t2
ON t1.child_id = t2.`entity_id`
Best Answer
Magento does not save product URLs completely in database tables. It saves only URL key, so you can get SKU and URL key directly from tables.
SKU is saved in
catalog_product_entity
table.By default product's URL key is an attribute which is of type varchar, so its value is saved in
catalog_product_entity_varchar
table. By default attribute id of product's URL key is 124.Please let me know if you want more detail.