AI Reports

Magento 2 SQL queries › Stock

Which products have never sold?

Short answer: No report shows this. Look for products with no line in sales_order_item.

In the Magento admin

  1. Compare the Bestsellers or Products Ordered report with a product export. Slow on big catalogues.

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, e.type_id AS type, e.created_at
FROM catalog_product_entity e
WHERE e.type_id IN ('simple', 'virtual', 'downloadable')
  AND NOT EXISTS (SELECT 1 FROM sales_order_item i WHERE i.product_id = e.entity_id)
ORDER BY e.created_at;

Adobe Commerce

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

SELECT e.sku, e.type_id AS type, e.created_at
FROM catalog_product_entity e
WHERE e.type_id IN ('simple', 'virtual', 'downloadable')
  AND NOT EXISTS (SELECT 1 FROM sales_order_item i WHERE i.product_id = e.entity_id)
  AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
ORDER BY e.created_at;

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