DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: SQL Query

  1. #1
    Join Date
    Nov 2002
    Location
    INDIA
    Posts
    38

    SQL Query

    We have a table which consist of following two fields

    Table name: Tab1
    Field1 Field3

    1 OK1

    1 OK2

    2 OK3

    2 OK4

    3 OK5

    For every Field1 value, We need to know the values of Field3 in a single row.

    Output has to be like this



    Field1 Field3(1) Field3(2)

    1 OK1 OK2

    2 OK3 OK4

    3 OK5 NULL


    Thanks In Advance

    Paddy

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Your example suggests a maximum of two possible values of field3 for each field1, in which case,

    select field1,
    min_field3 field3_1,
    case when max_field3 !=min_field3 then max_field3
    else null
    end field3_2
    from
    (
    select field1,
    min(field3) min_field3,
    max(field3) max_field3
    from tab1
    group by field1
    )

    The in-line view is not required, but it makes it a little clearer what is going on
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

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


Click Here to Expand Forum to Full Width