cancel
Showing results for 
Search instead for 
Did you mean: 

Query to retrive all products not having any sales history

Query to retrive all products not having any sales history

I need to write a query to retrive the list of products that do not have a sales history. Can someone help. Thank you

2 REPLIES 2

Re: Query to retrive all products not having any sales history

Hello @gayathri_madeti 

Please find below the query to retrieve the list of products that do not have any sales history:

 

SELECT sku FROM catalog_product_entity WHERE sku NOT IN (SELECT sku FROM sales_order_item)

 

Please let us know if you require any further assistance.

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9

Re: Query to retrive all products not having any sales history

In SQL:

 

SELECT *
FROM products
WHERE product_id NOT IN (
SELECT DISTINCT product_id
FROM sales
);

This query selects all rows from the products table where the product_id is not present in the subquery that selects all distinct product_id values from the sales table. By using a subquery, we can check for products that have no sales history and exclude them from the result set.

regards: London Tours

This query uses a subquery to first retrieve a list of distinct product IDs from the "sales" table. It then uses the NOT IN operator to retrieve all products from the "products" table whose IDs are not in this list, indicating that they do not have a sales history.