I have table in SQL Server called test having 3 column
| ITEM | ATTRIBUTE | VALUE |
-----------------------------
| item1 | Quality | A |
| item1 | color | Red |
| item2 | Quality | B |
| item2 | color | Black |
I want output like this:
| ITEM | QUALITY | COLOR |
---------------------------
| item1 | A | Red |
| item2 | B | Black |
How can I get this in SQL Server.
Try this one:
Output:
See this SQLFiddle
You can also use this dynamic query if you don't know the specific value of
attribute
:See this SQLFiddle
This is a bit of a hacky solution for mysql as PIVOT doesn't work in it.
Issue with this solution is that you should know all the distinct values of attribute column.
You can try it here.