I have the following two tables in my mysql database.
Table Name: groups
id group_name
1 Garments
2 Computer Accessories
3 Food
Table Name: account
id group_id account_name
1 1 T-shirt
2 1 Jeans
3 2 Motherboard
4 2 Mouse
What I am trying to display is like following:
Garments
T-Shirt
Jeans
Computer Accessories
Motherboard
Mouse
Food
I have tried the following query but could not make the output like above
SELECT group_name,accounts.account_name,accounts.id FROM `groups`
LEFT JOIN accounts ON accounts.group_id=groups.id
If I run the query it displays like following:
Garments T-Shirt
Garments Jeans
Computer Accessories Motherboard
Computer Accessories Mouse
Food NULL
Could you please show me how to display the output like I have mentioned above. Just for your information I am using Codeigniter.
Thanks a lot in advance 🙂
Here is the query for this purpose
Use group concat. This will display this result then you can explode accounts on php end