Assuming the following query where we are selecting values, grouping them and then re-grouping the result:
SELECT
CONCAT (b.label, '|', b.slug)
FROM (
SELECT
group_concat(name SEPARATOR '$') AS label,
group_concat(slug SEPARATOR '$') AS slug
FROM (
SELECT
color.name,
color.slug
FROM color
INNER JOIN product__colors USING ( color_id )
WHERE product__colors.product_id = 1 -- integer fixo funciona
) AS a
) AS b
Output example:
azul$vermelho$branco verde|azul$vermelho$branco-verde
But the query is to perform with the value of product__colors.product_id
variable and not 1
as in the example above:
SELECT
CONCAT (b.label, '|', b.slug)
FROM (
SELECT
group_concat(name SEPARATOR '$') AS label,
group_concat(slug SEPARATOR '$') AS slug
FROM (
SELECT
color.name,
color.slug
FROM color
INNER JOIN product__colors USING ( color_id )
WHERE product__colors.product_id = ? -- integer variável não funciona
) AS a
) AS b
Question
How can we pass a variable value to the innermost condition?