3
With this SQL I can in my database select and group products by variations that would be in this case different attributes for the same product.
Thus, when generating the product view, I have a dropdown in the product with all attributes that the customer can choose in a greater number of possibilities for the same product, for example a car that has several colors.
Here is the SQL:
$BuscaProdutosAtivos = $pdo->prepare("SELECT tbl_produtos.*, tbl_categorias.*,
GROUP_CONCAT(tbl_variacoes.valor) AS Variacoes FROM tbl_variacoes
INNER JOIN tbl_produtos ON tbl_produtos.id = tbl_variacoes.cod_prod
INNER JOIN tbl_categorias ON tbl_produtos.prod_categoria = tbl_categorias.cat_id
GROUP BY (tbl_produtos.id)");
With this SQL I return from tbl_variacoes
the column valor
. I’d like to return valor
, dimensao
, quantidade
because these three information will be concatenated inside the dropdown forming a variation. How can I do it using this SQL?
I figured if I could use several GROUP_CONCAT
but searching in some places I saw that it should not be done that way.
Every time you wear one
GROUP_CONCAT
for something that needs to break later, 100 people die of Ebola in Africa.– bfavaretto
Seriously now, it may be the case to make separate queries to catch these "variations". To answer more precisely I would need to see an example of what you want to put in such a dropdown.
– bfavaretto
Or simply concatenate these things in PHP, not Mysql. You can’t quite understand the question.
– bfavaretto