MySQL subselect in query -
i following results query:
id_product_attribute | id_product | reference | name | total 12 | 1 | 234235 | product_name | 2 14 | 2 | 235435 | product_name | 7 16 | 3 | 235325 | product_name | 4
etc
but when use query:
select pa.id_product_attribute, p.id_product, pa.reference, cl.name, sum(od.product_quantity) total ps_product_attribute pa left join ps_order_detail od on od.product_attribute_id = pa.id_product_attribute left join ps_product p on pa.id_product = p.id_product left join ps_category_product cp on cp.id_product = p.id_product left join ps_category_lang cl on cp.id_category = cl.id_category cp.id_category = 141 , cl.id_lang = 6;
it gives me results:
id_product_attribute | id_product | reference | name | total 12 | 1 | 234235 | product_name | 13
so in 'total' column shows me total of all, instead of seperate per row.
can tell me i'm doing wrong in query?
your source data help, @ least forgot group by
@ end. current query, should add;
group pa.id_product_attribute, p.id_product, pa.reference, cl.name
with mysql, can choose group by
less columns , random selection of values in other ones, if possible, should group by
columns don't have aggregates (like sum
in case) on them.
Comments
Post a Comment