Skip to content
Advertisement

Add rows to SQL table based on a list of values

So I have a table like this and an attribute list – ('attr1', 'attr2', 'attr3').

I want to make a query where this table can be “expanded” to be the following and then make a query using it.

The attribute list is given to me and dynamic.

Advertisement

Answer

Cross join the IDs and the attribute names and then left join the table to get the attribute values or NULL if no match was found.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement