1

I got a problem transforming a table that looks like this

PropertyName | PropertyValue --------------------------------- color red color blue size big size small 

into this:

Color | Size --------------------------------- red big red small blue big blue small 

How can I achieve this? Thanks in advance for any help.

1 Answer 1

1

You want every permutation of colours and sizes?

SELECT color, size FROM ( select distinct PropertyValue AS color from YourTable where PropertyName = 'color' ) T1 CROSS JOIN ( select distinct PropertyValue AS size from YourTable where PropertyName = 'size' ) T2 
Sign up to request clarification or add additional context in comments.

4 Comments

Okay, that`s a start. Thanks very much. But is there a way, to do it automatically for all PropertyNames and -Values? I mean without having to write a cross join for each propertyname?
Not in standard SQL. Can you tag your question with the RDBMS you are using.
Then I guess I have to live with it. Thanks again.
@tombom - For SQL server you would need to use dynamic SQL to create a string similar to the above that you then execute.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.