Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2014
    Posts
    3

    Unanswered: Displaying Columns as Rows

    I have a query that output students results for an exam. They do around 100 questions, so I was looking for an easy way of displaying the column results into rows, without using UNION as this would take a considerable amount of time.

    For example the following table

    Name | AA_Answer | BB_Answer | CC_Answer | DD_Answer | EE_Answer |
    -----------------------------------------------------------------------
    John | 27 | xyz | yellow | rhino | 2.3 |


    The query would result the following

    Name | Answer Name | Answer Output |
    --------------------------------------
    John | AA_Answer | 27 |
    John | BB_Answer | xyz |
    John | CC_Answer | yellow |
    John | DD_Answer | rhino |
    John | EE_Answer | 2.3 |

    Thanks for any help

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The are no PIVOT or UNPIVOT operators for MySQL, but your middle tier or client application might offer those features. If not, the performance difference between a "vanilla" SELECT and the UNION SELECT statements are trivial. Generating those UNION SELECT statements can be automated or scripted to make the process easier.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jun 2014
    Posts
    3
    Hi Pat,

    Thanks for your response I will do this!

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •