Jump to content

SQL to export Customer Emails - search via Product Name?


sampsonzak

Recommended Posts

Hi, I currently use the below code in PrestaShop Database/Admin back-end, and change the product id's to export groups of customers who have purchased specific items.

SELECT DISTINCT c.`email`
FROM `ps_customer` c LEFT JOIN `ps_orders` o ON (c.`id_customer` = o.`id_customer`) LEFT JOIN `ps_order_detail` od ON o.`id_order` = od.`id_order`
WHERE od.`product_id` IN (357,112);

 

I would like to change this code, to automatically find the products.

 

For example, to export all customers who ordered a product, where the product title contained "Football", for example.

 

Does anyone have a minute spare where they could make this? I don't want it to be an exact match, just if the product-name contains a keyword, to export their email address.

 

Thank you !!

Link to comment
Share on other sites

Found the solution and it works perfect. If anyone wants it, it's here:

 

Replace 'Football' with your keyword

 

SELECT DISTINCT c.`email`
FROM `ps_customer` c LEFT JOIN `ps_orders` o ON (c.`id_customer` = o.`id_customer`) LEFT JOIN `ps_order_detail` od ON o.`id_order` = od.`id_order`
WHERE od.`product_name` LIKE '%Football%';

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...