Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Location
    karachi , Pakistan
    Posts
    13

    Unanswered: Convert Column into Row

    hi
    i have a view that is created form multiple tables view structure is
    id col1 col2 col3 col4
    101 A B B NULL
    102 C F A G
    and so on (this is sample)

    i want to create another view that look like
    ID col_name value
    101 col1 A
    101 col2 B
    101 col3 B
    101 col4 NULL
    102 col1 C
    102 col2 F
    102 col3 A
    102 col4 G
    and so on

    can any one help plzzz

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    How about:

    Code:
    SELECT ID, 'col1' as col_name, col1 as value FROM table
    UNION
    SELECT ID, 'col2' as col_name, col2 as value FROM table
    UNION
    SELECT ID, 'col3' as col_name, col3 as value FROM table
    UNION
    SELECT ID, 'col4' as col_name, col4 as value FROM table;
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Apr 2011
    Location
    karachi , Pakistan
    Posts
    13

    Thumbs up Thanks

    it's Works

Tags for this Thread

Posting Permissions

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