E
E
Ellik2015-11-17 18:56:21
PHP
Ellik, 2015-11-17 18:56:21

How to merge request fields?

I will give as an example a piece of code that combines a group of attributes with the attributes and values ​​themselves into one line.

SELECT
     `entity`.`entity_name` as `entity_name`,
     GROUP_CONCAT(CONCAT(`group`.`title`, '-', CONCAT(`atr`.`attribute_name`, ':' , `val`.`value_name`))) as `attribute`
FROM `eav_entities` as `entity`
JOIN `products` as `products` ON (`entity`.`entity_id` = `products`.entity_id)
JOIN `eav_attributes` as `atr` ON (`products`.`attribute_id` = `atr`.`attribute_id`)
JOIN `eav_values` as `val` ON (`products`.`value_id` = `val`.`value_id`)
JOIN `group_attributes` as `group` ON (`atr`.`group_id` = `group`.`group_id`)
GROUP BY `entity`.`entity_name`

The result is:
Key Features-Name:ADATA Elite S102 Pro, Key Features-Manufacturer: ADATA, Key Features-Series: Elite S102 Pro, Key Features-Model: AS102P-256G-RGY, Key Features- Flash Drive Capacity: 256 GB ,Main specs-Colors used in design: Black,Main specs-Dimensions (width x height x depth): 62 x 19 x 11 mm,Main specs-Weight: 13 grams,Performance specs-Read speed: up to 100 Mbps ,Performance parameters-Write speed: up to 50 Mb / s
Ie . Group name - Attribute:Value, Group name - Attribute:Value, etc.
The solution is very "Wooden"... I'm not asking you to write me a solution, I just want to know the principle of solving such a problem.
PS Undertook to work withEAV data model, here I am reaping the benefits

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kotik Anton, 2015-11-18
@Ellik

It is possible like this:

SELECT
     `entity`.`entity_name`,
     `group`.`title`, 
     `atr`.`attribute_name`,
     `val`.`value_name`
FROM `eav_entities` as `entity`
JOIN `products` as `products` ON (`entity`.`entity_id` = `products`.`entity_id`)
JOIN `eav_attributes` as `atr` ON (`products`.`attribute_id` = `atr`.`attribute_id`)
JOIN `eav_values` as `val` ON (`products`.`value_id` = `val`.`value_id`)
JOIN `group_attributes` as `group` ON (`atr`.`group_id` = `group`.`group_id`);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question