Reputation: 79
I have 2 Tables and i need to hide a multiple result.
My Tables:
aID Name
1 aaa
2 bbb
aID Stuff
1 01
1 02
1 06
2 01
2 03
My result looks like this:
1 aaa 01
1 aaa 02
1 aaa 06
2 bbb 01
2 bbb 03
How can i display the result in HTML/PHP that it looks like this:
1 aaa 01,02,06
2 bbb 01,03
Upvotes: 0
Views: 42
Reputation: 1148
This is just the syntax change it as per your need. Hope this may help you.
select id, group_concat(`Name` separator ',') as `ColumnName`
from
(
select id, concat(`Name`, ':',
group_concat(`Value` separator ',')) as `Name`
from mytbl
group by id, `Name`
) tbl
group by id;
Upvotes: 0
Reputation: 457
Add this to your query
GROUP_CONCAT(Stuff) As Stuff //Where you select your Stuff
GROUP BY aID //At the end
Upvotes: 0
Reputation: 21437
Try using group_concat
along with group by
clause, instead of using HTML/PHP
you can simply get it from sql using query as
select a.aID, a.Name, Group_concat(b.stuff) as stuff
from user a join stuff b on a.aID = b.aID
group by aID
order by aID, Name ASC
Note: Table name are arbitrary over here please place your table names
Upvotes: 1