I have trouble creating what i can read from other threads is called a PIVOT table.
Think the answer is in this article http://stratosprovatopoulos.com/web-development/mysql/pivot-table-with-dynamic-columns/ but cant get my head around it
I have a table of products and a table of images One product can have many images.
If i helps lets say that one product can have up to 8 images.
PRODUCT
+----------+-------------+ |ProductId | ProductName | +----------+-------------+ | 1 | ProductA | +----------+-------------+ | 2 | ProductB | +----------|-------------+
IMAGE
+----------+-------------+ |ProductId | ImageName | +----------+-------------+ | 1 | FileA | +----------+-------------+ | 1 | FileB | +----------|-------------+ | 2 | FileC | +----------|-------------+
What I have now
SELECT p.ProductId, ProductName, ImageName
FROM PRODUCT p
LEFT JOIN IMAGE i
ON p.ProductId = i.ProductId
+----------+-------------+-----------+ |ProductId | ProductName | ImageName | +----------+-------------+-----------+ | 1 | ProductA | FileA | +----------+-------------+-----------+ | 1 | ProductA | FileB | +----------+-------------+-----------+ | 2 | ProductB | FileC | +----------+-------------+-----------+
What I need
+----------+-------------+---------+---------+ |ProductId | ProductName | Image1 | Image2 | +----------+-------------+---------+---------+ | 1 | ProductA | FileA | FileB | +----------+-------------+---------+---------+ | 2 | ProductB | FileC | | +----------+-------------+---------+---------+