combine multiple row/column results into one row

  • I did a bad job of explaining what I'm trying to do yesterday so I'll give it another try today.  I have the following table:

    id     key     val

    1       x        1

    1       y        1

    2       x        0

    2       y        1

    3       x        0

    3       y        0

     

    I need to present the result set as:

    id     key     val     key2   val2

    1       x        1        y        1

    2       x        0        y        1

    3       x        0        y        0

     

    Thanks in advance for advice........

  • If the table always contains two rows for each id, then this should work.

    SELECT t1.id, t1.key, t1.val, t2.key as key2, t2.val as val2

    FROM sometable t1

    INNER JOIN sometable t2 ON t1.id = t2.id

    WHERE t1.key = 'x'

    AND t2.key = 'y'

    But I guess it is not that simple. Maybe this will help you get started anyway.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply