MySQL row with multiple lines

  • hello guys, I think this could be simple I can't seem to find a solution.
    I have this table with multiple lines in a row.
    Ex:
    Table1
    id  Data1     Data2
    1    B1        100
          B2        50
    -----------------------
    2    M1        123
          M2        160
          M3        101
    ______________

    I need to create a query to combine those two columns in a new column but side by side.

    Desired output:
    CombineX
    B1-100
    B2-50
    M1-123
    M2-160
    M3-101

    select concat is okay if the data does not have multiple lines, but if the data has multiple lines, select concat output is not side by side.
    I don't need any conditions, I just want to combine or merge the 2 columns but it should be sideways, with a delimiter in between.

    Thank you for any help.

  • The MySQL data would appear to contain carriage return characters which can be handled with REPLACE.
    As for the layout, here is a starting point...

    select Data1 AS CombineX FROM Table1
    UNION ALL
    select Data2 FROM Table1
    LIMIT 30 ;

    again REPLACE can be used to turn a space into a dash ... 'B2 50' becoming 'B2-50'

    The below link gives good information on how to ask for help...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

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

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