I apologize for the lack of explanation on the title, as I do not know what to really call what I am trying to do, please modify if you know what I am looking for.
Here is my current table:
prodID | seller | price
123 seller1 5000
123 seller2 3000
123 seller3 5500
123 seller4 3500
500 seller2 55
500 seller5 60
200 seller1 35
200 seller2 25
200 seller3 35
Now I want to GROUP BY
prodID above and list each column as a the sellers price which could potentially be NULL
, ie:
prodID | seller1 | seller2 | seller3 | seller4 | seller5
123 5000 3000 5500 3500 null
500 null 55 null null 60
200 35 25 35 null null
I do not know how many unique sellers there are, so think of them as dynamic and not fixed.
I dont think I need a PIVOT TABLE
from what I have been researching, but please correct me if wrong. I have also tried a UNION
and combining the same table, but this seems inefficient as I dont know how many sellers there are and what their names are:
Inefficient:
SELECT
MT.prodID, MT.price, CT.price
from
`table` MT,
`table` CT
WHERE
MT.prodID = CT.prodID
AND MT.seller != CT.seller
GROUP BY MT.prodID