#magento #sql

Magento special price SQL

Get sepcial prices using SQL:

SELECT * FROM `catalog_product_entity_decimal`  as `price` 
INNER JOIN `eav_entity_type` AS `entity` ON `price`.`entity_type_id` = `entity`.`entity_type_id`
INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`

WHERE 
 `entity`.`entity_type_code` = 'catalog_product'
AND `attribute`.`attribute_code` = 'special_price'
AND `price`.`value` IS NOT NULL
ORDER BY `price`.`entity_id`  DESC

Update special prices in magento using sql

UPDATE `catalog_product_entity_decimal` AS `price`
INNER JOIN `eav_entity_type` AS `entity` ON `price`.`entity_type_id` = `entity`.`entity_type_id`
INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`
SET `price`.`value` = 123.0000
WHERE `price`.`entity_id` = 337
AND `entity`.`entity_type_code` = 'catalog_product'
AND `attribute`.`attribute_code` = 'special_price';