0

I try to execute this SQL-query, but I don't get the right result:

SELECT k.product_id,  product.sku, group_concat(i.value) 
FROM catalog_product_super_link AS par  
LEFT JOIN  staging.catalog_category_product k ON k.product_id = par.parent_id 
LEFT JOIN  catalog_product_entity AS product ON k.product_id = product.entity_id 
LEFT JOIN  catalog_category_entity_varchar AS p ON p.entity_id = k.category_id LEFT JOIN  catalog_category_entity_varchar i  ON i.entity_id = k.category_id 
WHERE  product.entity_id = 368538 
GROUP BY par.parent_id, k.category_id

Can someone help?

3
  • what is the result, and why is it wrong, and which result do you expect? Commented Oct 2, 2015 at 14:50
  • i get the categories in different rows, and i want to get them in one row, i tried with group_concat() but i didn t get the right result Commented Oct 2, 2015 at 15:22
  • you try to group_concat the column "value" from table "i", but I don't see a table "i" in your query. I think you might mean p.value, as "p" is the only table in your query that should have a column named "value" Commented Oct 2, 2015 at 16:41

1 Answer 1

0

Check the part where it says

catalog_category_entity_varchar i

It should be

catalog_category_entity_varchar AS i

Also this one:

staging.catalog_category_product k

Should be

catalog_category_product AS k

Unless you're using some kind of shorthand code that I don't know of.

8
  • 1
    "The AS keyword is optional when aliasing a select_expr with an identifier." dev.mysql.com/doc/refman/5.0/en/select.html Commented Oct 2, 2015 at 14:50
  • That's what I suspected. But still the staging.catalog_category_product k line is not correct I think. Commented Oct 2, 2015 at 14:51
  • I think he is using a different database for some of the tables Commented Oct 2, 2015 at 14:52
  • 1
    found it :) "You can refer to a table within the default database as tbl_name, or as db_name.tbl_name to specify a database explicitly" same link as above :) Commented Oct 2, 2015 at 14:54
  • Ok, but it can still be the cause of the issue :) Anyway, the best way to debug it is to split the query by removing parts, going through it step by step and see the resulting data. Commented Oct 2, 2015 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.