I currently have this statement...
SELECT *
FROM stock AS s
INNER JOIN stock_attributes AS sa ON sa.stock_code = s.stock_code
This outputs information like this...
| stock_code | attribute name | attribute value |
|------------|----------------|-----------------|
| ABC01 | color | red |
| ABC01 | size | small |
| ABC01 | price | 10.0 |
| XYZ99 | color | blue |
| XYZ99 | size | large |
| XYZ99 | price | 50.0 |
However I want it to look like this
| stock_code | color | size | price |
|------------|----------------|-----------------|------------------|
| ABC01 | red | small | 10.0 |
| XYZ99 | blue | large | 50.0 |
I have found many examples of this on SO but they seem to be extremely exact with complicated examples and was sure a function would exist for what I am trying to achieve above.
Currently I am achieving this with multiple INNER JOIN
s with a SELECT
in each one to pick the attribute names out however this needs manually amended when new attribute names are created.
Many thanks in advance!