0

I'm doing a code review for a search engine extension and am testing this query on my database:

SELECT product_id, SUM(value) FROM catalog_category_product_index 
LEFT JOIN catalog_category_entity_text vc 
ON category_id = vc.entity_id 
WHERE product_id = 5281 AND vc.attribute_id = 484

The results are:

product_id   SUM(value)
5281         24000

However, when I remove the product_id = 5281 clause and run this:

SELECT product_id, SUM(value) FROM catalog_category_product_index 
LEFT JOIN catalog_category_entity_text vc 
ON category_id = vc.entity_id 
WHERE vc.attribute_id = 484

I expect a list of all products with their corresponding values. Instead, I get this:

product_id   SUM(value)
4871         2143200

I'm obviously missing something, and it's probably something obvious. Any ideas?

1 Answer 1

1

SUM is an aggregate function. Appending a GROUP BY product_id should give the expected result.

0

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.