AI Reports

Magento 2 SQL queries › Products and catalogue

Which products still have a special price whose end date has passed?

Short answer: Magento stops applying a special price after special_to_date, but the value stays on the product. The query lists those leftovers.

In the Magento admin

  1. Filter the product grid by Special Price (add the column first) and open each product's Advanced Pricing.

With one query

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

Magento Open Source

SELECT e.sku, sp.value AS special_price, sto.value AS special_to_date
FROM catalog_product_entity e
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_special_price   ON a_special_price.entity_type_id   = t.entity_type_id AND a_special_price.attribute_code   = 'special_price'
JOIN eav_attribute a_special_to_date ON a_special_to_date.entity_type_id = t.entity_type_id AND a_special_to_date.attribute_code = 'special_to_date'
JOIN catalog_product_entity_decimal  sp  ON sp.entity_id  = e.entity_id AND sp.attribute_id  = a_special_price.attribute_id   AND sp.store_id  = 0
JOIN catalog_product_entity_datetime sto ON sto.entity_id = e.entity_id AND sto.attribute_id = a_special_to_date.attribute_id AND sto.store_id = 0
WHERE sp.value IS NOT NULL
  AND sto.value < CURRENT_DATE
ORDER BY sto.value;

Adobe Commerce

Product, category, rule and CMS values are stored per version and joined on row_id (why):

SELECT e.sku, sp.value AS special_price, sto.value AS special_to_date
FROM catalog_product_entity e
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_special_price   ON a_special_price.entity_type_id   = t.entity_type_id AND a_special_price.attribute_code   = 'special_price'
JOIN eav_attribute a_special_to_date ON a_special_to_date.entity_type_id = t.entity_type_id AND a_special_to_date.attribute_code = 'special_to_date'
JOIN catalog_product_entity_decimal  sp  ON sp.row_id  = e.row_id AND sp.attribute_id  = a_special_price.attribute_id   AND sp.store_id  = 0
JOIN catalog_product_entity_datetime sto ON sto.row_id = e.row_id AND sto.attribute_id = a_special_to_date.attribute_id AND sto.store_id = 0
WHERE sp.value IS NOT NULL
  AND sto.value < CURRENT_DATE
  AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
ORDER BY sto.value;

Good to know

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn