Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show each value in different rows

How can i show values from different columns in new rows?
Lets say i have:

o_id type color
1 product red
2 object green

And i want my result to look like this:

o_id Attribute
1 product
1 red
2 object
2 green

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

One simple approach uses a union:

SELECT o_id, type AS Attribute, 1 AS pos FROM yourTable
UNION ALL
SELECT o_id, color, 2 FROM yourTable
ORDER BY o_id, pos;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading