0

I have a table like below

id | main_id       | image
1  | 10            | 52343.jpg   
2  | 10            | 52344.jpg  
3  | 10            | 52345.jpg 
4  | 11            | 52346.jpg   
5  | 11            | 52347.jpg  
6  | 11            | 52348.jpg 
7  | 11            | 52349.jpg   
8  | 12            | 52350.jpg  
9  | 12            | 52351.jpg 

i want output like this :

id | main_id  | image1    
1  | 10       | 52343.jpg, 52344.jpg, 52345.jpg 
2  | 11       | 52346.jpg, 52347.jpg, 52348.jpg, 52349.jpg 
3  | 12       | 52350.jpg, 52351.jpg 

Just all images with same main_id to be in one row.

Ahmed Maher
  • 103
  • 1
  • 10
  • https://stackoverflow.com/questions/13451605/how-to-use-group-concat-in-a-concat-in-mysql – Anil May 13 '19 at 06:31
  • Possible duplicate of [How to use GROUP\_CONCAT in a CONCAT in MySQL](https://stackoverflow.com/questions/13451605/how-to-use-group-concat-in-a-concat-in-mysql) – TechWisdom May 13 '19 at 07:10

1 Answers1

1

use group_concat()

select main_id,group_concat(image)
from tablename
group by main_id
Fahmi
  • 37,315
  • 5
  • 22
  • 31
  • It works fine, but I noticed that that there are max number of characters that the 'image' cell can accommodate. i.e. if there are 100 jpg file name to be accommodated, it can only store limited number with fixed characters and the rest do not show. Any idea? – Ahmed Maher May 13 '19 at 14:25
  • How to put results in multi columns i.e. image1, image2, image3 ..... not in image column only? – Ahmed Maher May 13 '19 at 23:48