0

I have table which have these fields patchno, Project_no Item_Desc Quantity Store Action And currently it looks like this:

enter image description here

I expect to be as this:

enter image description here

Every patch_no must have unique project_no and store other two columns are variety. My array variable which is PHP if I use print_r($orders) it outputs this.

Array ( [0] => stdClass Object ( [ID] => 1 [patchno] => 1 [item_id] => 1 [Quantity] => 10 [store_id] => 1 [project_id] => 1 [user_id] => 1 [order_date] => 2015-10-22 14:55:51 [Desc] => Jiingado [Cost] => 6.60 [store_name] => Nuux [Telephone] => 565656 [email] => [email protected] [address] => Gacanlibaax [Project_No] => 466 [Site] => A [owner] => Gaboose [foreman] => Axmed Diiriye ) [1] => 
 stdClass Object ( [ID] => 1 [patchno] => 1 [item_id] => 3 [Quantity] => 2 [store_id] => 1 [project_id] => 1 [user_id] => 1 [order_date] => 2015-10-22 14:55:51 [Desc] => Marmar [Cost] => 1.00 [store_name] => Nuux [Telephone] => 565656 [email] => [email protected] [address] => Gacanlibaax [Project_No] => 466 [Site] => A [owner] => Gaboose [foreman] => Axmed Diiriye ) [2] => stdClass Object ( [ID] => 1 [patchno] => 1000002 [item_id] => 2 [Quantity] => 21 [store_id] => 1 [project_id] => 1 [user_id] => 1 [order_date] => 2015-10-24 15:34:52 [Desc] => Masaabiir [Cost] => 2.00 [store_name] => Nuux [Telephone] => 565656 [email] => [email protected] [address] => Gacanlibaax [Project_No] => 466 [Site] => A [owner] => Gaboose [foreman] => Axmed Diiriye ))

the query that outputs these value is this:

SELECT orders.*, items.*, stores.*, projects.*
            FROM orders
            join items on items.ID=orders.item_id
            join stores on stores.ID=orders.store_id
            join projects on projects.ID=orders.project_id
0

1 Answer 1

1

Use group_concat to get a comma separated string of all the "variety" values in the group and the unique values of the group should be specified in your group by:

select patchno, Project_no, group_concat(Item), group_concat(Quantity), store
from orders
join items on items.ID=orders.item_id
join stores on stores.ID=orders.store_id
join projects on projects.ID=orders.project_id
group by patchno, project_no, store
Sign up to request clarification or add additional context in comments.

3 Comments

Dear Sir @Fuzzy Tree, so i have to concat the variety fields
@Saedawke yes but group_concat will only work on mysql
does this will effect my joining tables ?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.