MYSQL for selecting values from table and show with comma separator -


i have 2 tables:

sales table

    ===============================     id     cust_id     total_price     ===============================     1       1           1000              2       2           1500 

sales_item table

    ======================================================     id     sales_id     cust_id     product     quantity     ======================================================     1       2           2           pen             2      2       2           2           pencil          3      3       1           1           book            2      4       1           1           pencil          2 

i need query these 2 tables inorder following result:

    =========================================     sales_id     cust_id     product     =========================================     2               2           pen,pencil            1               1           book,pencil 

can me query these 2 tables inorder above result??

i tried using group_concat. hers have tried:

    select s.id,s.cust_id,s.total_price,      group_concat(i.prdt_name)products      sales s      join sale_items on s.id=i.sales_id  

and result got is:

    ======================================================     id     cust_id     total_price      product      ======================================================     2       2           1500            pen,pencil,book 

this not result expecting..

try this, consider not tested, may you.

select sales.id,sales.cust_id, concat(sales_item.product)  sales left join sales_item on sales_item.sales_id = sales.id group sales.id 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -