php - mysql group_by only returns first row -


i'm new here , and need mysql query.

i have query retrieve several rows in join query.

select   category.category, category_color.color, sum(sales.quantity) quantity, sum(sales.price) total, sales.id_payment_type,                     sales.price                 sales             inner join                  category        using (id_category)             inner join                  shop_session    using (id_shop_session)             inner join                  category_color  using (id_category)             shop_session.is_active = 1             , category.id_lang = "._id_lang_."             , shop_session.id_shop = ".$_session['id_shop']."             group category.category             order category.category 

i've achieved grouping category first purpose , when need retrive data "price" or "id_payment_type" mysql returns first row, , need rows query. don't know how can solve query. please help!

my sales db structure:

create table if not exists `sales` ( 

id_sale int(11) not null auto_increment, id_product int(11) unsigned not null, id_category int(11) unsigned not null, id_employee int(11) unsigned not null, id_payment_type int(11) unsigned not null, id_sale_type int(11) unsigned not null, id_shop_session int(11) unsigned not null, position int(11) not null, quantity int(11) not null, price decimal(17,2) not null, amount float not null, invoice int(1) not null, note varchar(150) collate utf8_unicode_ci not null, date_sale int(11) default null, primary key (id_sale,id_product,id_category,id_employee,id_payment_type,id_sale_type,id_shop_session), key id_sale (id_sale) )

and db structure category table:

create table if not exists `category` ( 

id_category int(10) unsigned not null, id_lang int(10) unsigned not null, category varchar(30) collate utf8_unicode_ci not null, is_active int(1) not null )

select   category.category, category_color.color, sum(sales.quantity) quantity, sum(sales.price) total, sales.id_payment_type, sales.price sales inner join  category        using (id_category) inner join  shop_session    using (id_shop_session) inner join  category_color  using (id_category) shop_session.is_active = 1 , category.id_lang = "._id_lang_." , shop_session.id_shop = ".$_session['id_shop']." group category.category order category.category 

this query give first row of every category have because using group , first because using order implicit asc.

if want id_payment_type or prices of every category can't group by.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -