I did research the question (Combine Multiple child rows into one row MYSQL), but none of them is the same as mine. I need a solution, but I don't have any conditions. I see the pivot table examples, but they all use conditions or hardcoding, for example see below:
GROUP_CONCAT(if(colID = 1, value, NULL))
OR
Round(Sum(If( Month(o.orderdate)= 1, (d.unitprice*d.quantity)-d.discount, 0 )), 2 ) AS Jan,
They all use either Max/min, concat or hard coding of id values. In my case, The id's are retrieved from a SQL query, based on another id in the where clause. There can be zero images or 10 per advertiser id. Please see the image below of what I am trying to achieve. IF anybody feels it to be a duplicate, please point me to the correct answer?
Basically, I have 3 tables, that I am joining into 1, with a select query using joins, my MySQL is below:
select a.PK , a.Name, a.Email, i.Image_Name
FROM `advertiser` a
LEFT JOIN category c ON a.PK = c. FK
LEFT JOIN images I on a.PK = i.FK
where c.FK = 1
Now, my result is something like this:
PK Name Email Image_name
31 Sprouts info@Sprout.co.za Sprouts.jpg
31 Sprouts info@Sprout.co.za Bananas.jpg
31 Sprouts info@Sprout.co.za Apples.jpg
31 Sprouts info@Sprout.co.za Lemos.jpg
Where what I want is:
PK Name Email Image_name_1 Image_name_2 Image_name_3 Image_name_4
31 Sprouts info@Sprout.co.za Sprouts.jpg Bananas.jpg Apples.jpg Lemos.jpg
All the images on one row per PK.
Any help will be greatly appreciated.