Click Fraud Protection
PHP related blog, freelancer to hire!

How to return all magento product SKUs in one SQL?

Sometimes when you create some cart rules in magento you want to use condition that product SKU “is not one of”

you can insert comma separated list of SKUs there

to give you just idea look below

 

connect to your database from CLI or use phpMyAdmin

then

 

First enable long string returns (adjust as required):

SET SESSION group_concat_max_len = 54000;

Then magic SQL query

SELECT GROUP_CONCAT(catalog_product_entity.sku SEPARATOR ', ') FROM catalog_category_product  LEFT JOIN catalog_product_entity ON catalog_product_entity.entity_id = product_id  WHERE category_id ='YOUR_CATEGORY_ID';

And revert change (to whatever value you’ve had before)

SET SESSION group_concat_max_len = 1024;

You can use GROUP_CONCAT for any other queries when you need to return results as one string

 

 

Leave a Reply