0
Create Procedure `SelectProduct` (IN prod VARCHAR(70)) 
BEGIN

SET @sql = null;

SELECT GROUP_CONCAT(DISTINCT CONCAT( 'max(case when Attribute = ''',Attribute,'" Then p.Attributevalue end) as `',Attribute,'`' )  
INTO @sql FROM tblAttribute;

SET @sql = CONCAT('Select pr.product, ',@sql,' from tblproduct tblproduct pr LEFT JOIN tblproductattribute p using(productid) left join tblattribute a using (attributeid)
where pr.product LIKE (''%',prod,'%'') group by pr.productid ');
Prepare st from @sql;
execute stmt; 
END 

Please help me,the procedure about output columns like this

|Product|Width|Color|Size| 

what i need is like this

|Product|Product description|
sampleproduct|13mm,Green,Small

Edited by pritaeas: Fixed markdown.

2
Contributors
1
Reply
23
Views
3 Years
Discussion Span
Last Post by LastMitch
0

what i need is like this

@bumbumpaw

I'm not sure if anyone will be able to create a query like that?

If your table structure is like this:

|Product|Width|Color|Size| 

but you want it to group:

|Product|Product description|

Can you be specific why you need to group that like? On many e-comm platform, they have their own are mysql query to do that, it should be in the guideline.

If you want to echo out the data from the front to look like this:

|Product|Product description|
sampleproduct|13mm,Green,Small

Then create it I don't see any issue with that but if your intention to group your data or reorganized the table structure is a bit hard, it involve more than just a query.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.