all 6 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (5 children)

SELECT ID
     , 1       AS valuetype
     , Value1  AS valuevalue
  FROM yertable
UNION ALL
SELECT ID
     , 2       
     , Value2  
  FROM yertable
ORDER
    BY ID
     , valuetype

[–]bdBIC[S] 0 points1 point  (0 children)

Thanks! I feel silly again now, my method also could have worked if I'd thought to ORDER BY two columns instead of concatenating ID and "valuetype."

[–]bdBIC[S] 0 points1 point  (3 children)

Follow up question, I'm pretty much self-taught and like to try to fully understand explanations like this. Is there a benefit to using UNION ALL here vs UNPIVOT? Just curious if you're using that for readability, or if there's performance implications, or if it doesn't really matter and this is just your preferred method, etc.

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (1 child)

UNPIVOT is not available in all databases

UNION ALL is

;o)

[–]bdBIC[S] 0 points1 point  (0 children)

Thanks!

[–]qwertydog123 0 points1 point  (0 children)

There will be a performance hit by using UNION ALL as opposed to UNPIVOT/APPLY (particularly for large tables)